I'm pulling records from the database and created a PHP file to execute when then "delete" button is pressed. The code works in the sense that it deletes the records from the database but it always deletes the first record in the database and not the one relating to the Request ID thats in the table. Any help would be great
Table:
<?php
//3. Perform database query
$result = mysql_query("SELECT * FROM Request
WHERE DepID = 'CO'
AND Status = 'P'", $connection);
if(!$result){
die("Database query failed: " . mysql_error());
}
//4. Use Returned Data
while ($row = mysql_fetch_array($result)) {
$row['ReqID'];
echo "<tr>";
echo "<td class='req' align='center'>".$row['ReqID']."</td>";
echo "<td class='req' align='center'>".$row['ModTitle']."</td>";
echo "<td class='req' align='center'>".$row['BuildingID']."</td>";
echo "<td class='req' align='center'>".$row['RoomID']."</td>";
echo "<td class='req' align='center'>".$row['Priority']."</td>";
echo "<td class='req' align='center'>".$row['W1']."</td>";
echo "<td class='req' align='center'>".$row['P1']."</td>";
echo "<td class='req' align='center'><a href=''><img height='18px' src='images/edit.png'></a></td>";
echo "<td class='req' align='center'><a href='deletereq.php'><img src='images/exit.png'></a></td>";
echo "</tr>";
}
?>
And then this is the deletereq.php file:
<?php require_once("includes/connection.php"); ?>
<?php
//3. Perform database query
$result = mysql_query("SELECT * FROM Request
WHERE DepID = 'CO'
AND Status = 'P'", $connection);
if(!$result){
die("Database query failed: " . mysql_error());
}
//4. Use Returned Data
while ($row = mysql_fetch_array($result)) {
$row['ReqID'];
$result2 = mysql_query("DELETE FROM Request
WHERE ReqID = {$row['ReqID']} LIMIT 1", $connection);
if (mysql_affected_rows() == 1) {
redirect_to("content.php");
} else {
//deletion failed
echo "<h1>Request Deletion Failed.</h1>";
echo "<p>" . mysql_error() . "</p>";
echo "<a href=\"request.php\"> Return to request</a>";
}
}
?>
<?php mysql_close($connection); ?>