I hvae been working on this code for hours and can't figure out how to delete information from a database. It is currently claiming that result and checkbox aren't variables... I have looked at countless websites but can't seem to get this to work.
Thank you ahead of time.
<head>
<title>Lost Furry Friends</title>
<link type="text/css" rel="stylesheet" href="LFF.css">
</head>
<body>
<table border="0" width="100%">
<tbody>
<tr>
<td colspan="4"><div id="csl_site_title" ><br /><center>Lost Furry Friends (LFF) Program</center><br /></div></td>
</tr>
<tr>
<td width="25%"><center><div id="csl_navigation"><a href="intro.html">Introduction</a></div></center></td>
<td width="25%"><center><div id="csl_navigation"><a href="Lost.php">Lost</a></div></center></td>
<td width="25%"><center><div id="csl_navigation"><a href="Found.php">Found</a></div></center></td>
<td width="25%"><center><div id="csl_navigation"><a href="New_Entry.php">New Entry</a></div></center></td>
</tr>
<tr>
<td colspan="4">
<div id="csl_page_title">
<br /><p><center>Administration Page</center><p>
<center><br><input name="delete" type="submit" id="delete" value="Delete"></td><br></center>
</div>
</td>
</tr>
</tbody>
</table>
<table border="1" style="width:100%">
<tr>
<?php
//Create a new mysqli connection
@ $db = new mysqli('localhost', 'root', 'secret', 'Final');
if ($db->connect_error) {
echo 'ERROR: Could not connect to database, error is '. $db->connect_error;
exit;
}
//Make a query against the MySQL server, and store that result
//in resultset $res
$res = $db->query("SELECT * FROM PET RIGHT JOIN Pet_Color USING (Pet_ID)
JOIN Color USING (Color_ID)
LEFT JOIN Species USING(Species_Number)
Left Join location using(PET_ID)");
//Check to make sure the query succeeded
if (!$res) {
echo $db->error . '<br/>';
exit;
}
//Store the result in an associative array
$result_array = $res->fetch_all(MYSQLI_ASSOC);
//Create the table to report results
?>
<table border="1">
<tr>
<td><b>Delete?</b></td>
<td><b>ID</b></td>
<td><b>Picture</b></td>
<td><b>Name</b></td>
<td><b>Colour</b></td>
<td><b>Gender</b></td>
<td><b>Behaviour</b></td>
<td><b>Date</b></td>
<td><b>Birthday</b></td>
<td><b>Status</b></td>
<td><b>Specie</b></td>
<td><b>Address</b></td>
</tr>
<?php
foreach ($result_array as $row){
$i=0;
?>
<tr>
<td><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['Pet_ID']; ?>"></td>
<td><?php echo $row['Pet_ID']?></td>
<td><?php echo $row['Pet_Image']?></td>
<td><?php echo $row['Pet_Name']?></td>
<td><?php echo $row['Color_Description']?></td>
<td><?php echo $row['Pet_Gender']?></td>
<td><?php echo $row['Pet_Behavior']?></td>
<td><?php echo $row['Pet_Date']?></td>
<td><?php echo $row['Pet_Birthday']?></td>
<td><?php echo $row['Pet_Status']?></td>
<td><?php echo $row['Species_Name']?></td>
<td><?php echo $row['Location_Address']?> <?php echo $row['Location_State']?>, <?php echo $row['Location_Zip']?></td>
</tr>
<?php
}
?></table><?php
if(isset($_POST['delete']))
{
if(count($_POST['checkbox']) !=0)
{
$array = array("checkbox" => $_POST['checkbox']);
$ids = implode(',', $array);
$result = mysql_query("DELETE FROM $Pet WHERE Pet_ID IN($ids) ") or die(mysql_error());
}
}
if($result){
echo "<meta http-equiv=\"refresh\" content=\"0;URL=delete_multiple.php\">";
}
//Clean up
$res->close();
//Close the connection
$db->close();
?>
</tr>
</table>
</body>
</html>