I cannot delete the records after pressing the delete button. What is the fatal error? Thanks!
admin.php
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="test"; // Database name
$tbl_name="test_mysql"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
?>
<form id="form" name="form" method="post" action="deleteApplication.php"><table border='1' cellspacing='0' width='612'>
<tr>
<th bgcolor='green'><font color='white'>#</font></th>
<th bgcolor='green'><font color='white'>Id</font></th>
<th bgcolor='green'><font color='white'>Name</font></th>
<th bgcolor='green'><font color='white'>Lastname</font></th>
<th bgcolor='green'><font color='white'>Email</font></th>
</tr>
<?php
$i = 0;
$number = 0;
while($row = mysql_fetch_array($result)){
$number++;
?>
<?php
$i++;
if($i%2)
{
$bg_color = "#EEEEEE";
}
else {
$bg_color = "#E0E0E0";
}
?>
<tr bgcolor='". $bg_color ."'>
<td><center><Strong><font color='red'><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<?php echo $rows['id']; ?>">
</font></Strong>
</center></td>
<td><center><Strong><font color='red'><?php echo $row['id']; ?></font></Strong></center></td>
<td><center><Strong><?php echo $row['name']; ?></font></Strong></center></td>
<td><center><Strong><?php echo $row['lastname']; ?></Strong></center></td>
<td><center><Strong><?php echo $row['email']; ?></Strong></center></td>
</tr>
<?php } ?>
</table>
<div class="select"><strong>Other Pages: </strong>
<select>
<option>1</option>
</select>
</div>
<label>
<input name="delete" type="submit" id="delete" value="Delete">
</label></form>
deleteApplication.php
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="test"; // Database name
$tbl_name="test_mysql"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
if(isset($_POST['delete'])) {
foreach($_POST['checkbox'] as $id){
mysql_query("DELETE from $tbl_name WHERE id ='.$id.'");
}
header('Location: admin.php');
}
?>