Deleting a ROW from MySQL database using MySQLi

John B

I've got a delete.php file with yes/no buttons that call deleteRecord.php to delete the selected row from the database.

The problem seems to be that I'm not passing the variable for the ProjectID through to the deleteRecord file.

Can someone please tell me what's wrong?


delete.php

<?php 
error_reporting(E_ALL|E_STRICT); ini_set('display_errors', true);
require('includes/conn.inc.php');
require('includes/functions.inc.php');
$sProjectID = safeInt($_GET['ProjectID']);
$stmt = $mysqli->prepare("SELECT ProjectID, ProjectName, ProjectImage, LanguageUsed, ApplicationUsed, Description FROM Projects WHERE ProjectID = ?");
$stmt->bind_param('i', $sProjectID);
$stmt->execute(); 
$stmt->bind_result($ProjectID, $ProjectName, $ProjectImage, $LanguageUsed, $ApplicationUsed, $Description);
$stmt->fetch();
$stmt->close();
?>
<!DOCTYPE HTML>
<input name="ProjectID" type="hidden" value="<?php echo
$ProjectID; ?>">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Delete <?php echo $ProjectName; ?></title>
<link href="styles/cms.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="container">
<header>
<h1>Delete <?php echo $ProjectName; ?></h1>
<?php
require('includes/nav.inc.php');
?><p>Hello </p><?php echo "$sProjectID" ?>
</header>

<form name="form1" method="get" action="process/deleteRecord.php">
<p>Are you sure you wish to delete <?php echo $ProjectName; ?>?</p>
   <p>
    <input type="submit" name="del" id="del" value="Delete">
  </p>
    </form>

<form name="form2" method="" action="listall.php" id="saveForm">
    <input type="submit" name="save" id="save" value="Save">
</form>

<?php
require('includes/footer.inc.php');
?>

</div>
    </body>
    </html>

deleteRecord.php

<?php
error_reporting(E_ALL|E_STRICT); ini_set('display_errors', true);
require('../includes/conn.inc.php');
require('../includes/functions.inc.php');
// sanitize user variables
$sProjectID = safeInt($_POST['ProjectID']);
// prepare SQL
$stmt = $mysqli->prepare("DELETE FROM Projects WHERE ProjectID = ?");
$stmt->bind_param('i', $sProjectID);
$stmt->execute();
$stmt->close();
//header("Location: ../index.php");
// redirect browser
exit;
// make sure no other code executed
?>
Saty

You need to write the hidden field inside your form and change your method to POST.

<form name="form1" method="post" action="process/deleteRecord.php">
    <p>Are you sure you wish to delete <?php echo $ProjectName; ?>?</p>
    <p>
        <input name="ProjectID" type="hidden" value="<?php echo
$ProjectID;
?>">
        <input type="submit" name="del" id="del" value="Delete">
    </p>
</form>

As per @VolkerK comment below, put the input element "within" the form element instead of the one before the <html> tag.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

deleting row from database using C#

From Dev

Deleting mysql database row

From Dev

Deleting database row using Ajax

From Dev

Row not deleting from SQLite Database

From Dev

Deleting row from database using html hyperlink servlet

From Dev

Deleting row using PHP Mysql

From Dev

Deleting specific row from a table in MySQL using PHP

From Dev

SQLException deleting row from JTable and database

From Dev

Deleting Row from users table PHP MYSQL

From Dev

AJAX/Jquery not deleting row from MySQL table

From Dev

Deleting row from CSV using python

From Dev

Deleting row in database

From Dev

Deleting row in database

From Dev

Deleting comments from database using php

From Dev

How to extract desired row from Mysql database using PHP script

From Dev

Select single row from database using mysql connector .NET

From Dev

How to extract desired row from Mysql database using PHP script

From Dev

Using database TEXT to IMAGE using mysqli_fetch_row

From Dev

Using database TEXT to IMAGE using mysqli_fetch_row

From Dev

Fetch all results from database using mysqli

From Dev

Fetch all results from database using mysqli

From Dev

How to select information from more then one table in MySQL Database using PHP and mySQli, has to be combined single query

From Dev

Deleting a row in a Oracle 11g database using NetBeans

From Dev

Deleting a row with Php & MySQL

From Dev

MySql - Deleting a row

From Dev

MySql - Deleting a row

From Dev

Deleting a row with Php & MySQL

From Dev

select one radio button from each row and then submit it to database mysqli

From Dev

Deleting MySQL database with a "-" in the name