Hi there,
I am trying to implement a confirmation dialog box before deleting a record in a table that
have.
I created a MYSQL table called manager with columns:
Table manager
managerID
firstName
lastName
Department
I use a while loop to display the records of every manager in the database a "delete this
manager" link next to each record.
If the user clicks the "delete this manager" a html form is called prompting the user if he
wants indeed to delete that manager.
If yes,I get the following error:
Error deleting manager: You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near '' at line 2
Here are extracts of my code(manager.php):
<?php
$result = @mysql_query('SELECT managerID,FirstName,LastName,Department FROM manager');
if (!$result) {
exit('<p>Error performing query: ' .
mysql_error() . '</p>');
}
while ($row = mysql_fetch_array($result)) {
$managerID = $row['managerID'];
$FirstName = $row['FirstName'];
$LastName = $row['LastName'];
$Department = $row['Department'];
echo "<tr><td>";
echo $managerID;
echo "</td><td>";
echo $FirstName;
echo "</td><td>";
echo $LastName;
echo "</td><td>";
echo $Department;
echo "</td><td>";
echo "<a href='delete_manager.php?mGinNo=$mGinNo'>Delete this manager</a>";
echo "</td></tr>";
}//end of while-loop
?>
Extracts of delete_manager.php:
<html>
<p>Are you sure you want to delete this manager?</p>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
Your choice: <input type="radio" name="choice" value="yes"> Yes <input type="radio"
name="choice" value="no" /> No
<button type="submit">Send</button>
</form>
<?php
// Connect to the database server.
// Select the trainee_allocation database
require('connectdatabase.inc.php');
if (isset($_POST['choice']) ) {
switch($_POST['choice']) {
case 'yes':
/// Code here
$mGinNo = $_POST['mGinNo'];
$sql = "DELETE FROM manager
WHERE mGinNo=$mGinNo";
if (@mysql_query($sql)) {
echo '<p>The manager has been deleted.</p>';
} else {
echo '<p>Error deleting manager: ' .
mysql_error() . '</p>';
}
break;
case 'no':
/// Code here
break;
default:
/// Error treatment
break;
}
}
else {
// error treatment
echo "error";
}
?>
</html>
Could anyone have a look at my code and tell me what I am doing wrong?
Thank you