hi.........
my php code for deleting records from database is working succesfully but while deleting records from database using checkbox is that only records deleted when deleting button click on two time.... means clicking delete button twice delete the record...... plz chk my code nd tell whr is mistake??????????????
plz reply me within 24 hrs
<?php
$dbhost="localhost";
$dbuser="root";
$dbpass="root";
$dbname="test";
mysql_connect("$dbhost","$dbuser","$dbpass") or die('Could not connect');
mysql_select_db($dbname);
?>
<form name="form1" method="post" action="">
<table width="918" border="0">
<tr>
<td> sno</td>
<td>FirstName</td>
<td>LastName</td>
<td>Age</td>
</tr>
<?php
$query="SELECT * FROM student";
$result=mysql_query($query);
$sno=1;
while($row=mysql_fetch_array($result, MYSQL_ASSOC)){
?>
<tr>
<td><? echo $sno;?></td>
<td><? echo $row['FirstName'];?></td>
<td><? echo $row['LastName'];?></td>
<td><? echo $row['Age'];?></td>
<td><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $row['LastName']; ?>"></td>
</tr>
<?
$sno=$sno+1;
}
?>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td colspan="2"><div align="center">
<input name="delete" type="submit" id="delete" value="Delete Records">
</div></td>
</tr>
</table>
<?
if($_POST['delete']){
//print_r($_POST);
$checkbox=$_POST['checkbox'];
//exit;
for($i=0;$i<count($checkbox);$i++){
$FirstName = $checkbox[$i];
$sql = "DELETE FROM student WHERE FirstName='$FirstName'";
$result = mysql_query($sql);
}
// if successful redirect to delete_multiple.php
/*if($result){
echo "<meta http-equiv=\"refresh\" content=\"0;URL=deletemultiplerecords.php\">";
} */
}
?>
</form>