hello, i'm having trouble getting my delete selected checkbox working for a code I'm writing:
the trouble is really just in the bottom half of the code after i make the while loop...i made this off of an example that i found on a site but like it was pretty clear that the site's code had many errors for example...the coder made an input tag and later called it as a $variable which i'm pretty sure isn't possible..anyways some help would be much appreciated :)
<?php
//create a database connection
mysql_connect("localhost", "root","") or die(mysql_error());
//select your database
mysql_select_db("group1");
?>
<html>
<body background="schoolbackground.jpg">
<div style="border-bottom-style: solid; border-bottom-width: 1px; padding-bottom: 1px">
<font color="#357EC7" size="7" face="century gothic">Student Delinquent List</font></div>
<p> </p>
<a href="textbook_teachhome.htm">
<p align="right">
<button type="button"><font face="century gothic" size="2" color="#357EC7">Go Back</font></button></a>
</p>
<p align="center">
<?php
$query = mysql_query("SELECT * from r_textbook_info");
$count = mysql_num_rows($query);
?>
<table frame="border" rules="all" cellpadding="5" bgcolor="#FFFFFF">
<tr>
<th></th>
<form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<th>Student Number</th>
<th>Course</th>
<th>Year</th>
<th>Book ID</th>
<th>Book Name</th>
<th>Cost</th>
</tr>
<?php
//return the array
while ($row = mysql_fetch_array($query)){
$sn = $row['student_number'];
$course = $row['course'];
$year = $row['year'];
$bid = $row['book_id'];
$bname = $row['book_name'];
$cost = $row['cost'];
?>
<tr>
<th><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $bid; ?>"/></th>
<th><? echo $sn; ?></th>
<th><? echo $course; ?></th>
<th><? echo $year; ?></th>
<th><? echo $bid; ?></th>
<th><? echo $bname; ?></th>
<th><? echo $cost; ?></th>
</tr>
<?php
}
?>
</table>
<?php
// Check if delete button active, start this
if(isset($_POST['delete'])){
for($i=0;$i<$count;$i++){
if(isset($_POST['checkbox[]']))
{$del_id = $bid[$i];
echo $del_id;
$sql = "DELETE FROM r_textbook_info WHERE id='$del_id'";
$result = mysql_query($sql);}
}
// if successful redirect to delete_multiple.php
if($result){
echo "<meta http-equiv=\"refresh\" content=\"0;URL=teach_delinquent.php\">";
echo "SUCCESS";
}
}
mysql_close();
?>
<input name="delete" type="submit" id="delete" value="Delete"/>
</p>
</form>
</html>