Jump to content

[SOLVED] multiple delete


saradrungta

Recommended Posts

can some 1 help in finding error in below code its not deleting data from DB

 

 

 

<?php

// Connect to server and select databse.

mysql_connect("localhost","root","")or die("cannot connect");

mysql_select_db("sarad")or die("cannot select DB");

 

$sql="SELECT * FROM studentrec";

$result=mysql_query($sql);

 

$count=mysql_num_rows($result);

 

?>

<table width="400" border="0" cellspacing="1" cellpadding="0">

<tr>

<td><form name="form1" method="post" action="adelete.php">

<table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">

<tr>

<td bgcolor="#FFFFFF"> </td>

<td colspan="4" bgcolor="#FFFFFF"><strong>Delete multiple rows in mysql</strong> </td>

</tr>

<tr>

<td align="center" bgcolor="#FFFFFF">#</td>

<td align="center" bgcolor="#FFFFFF"><strong>Id</strong></td>

<td align="center" bgcolor="#FFFFFF"><strong>Name</strong></td>

<td align="center" bgcolor="#FFFFFF"><strong>Age</strong></td>

<td align="center" bgcolor="#FFFFFF"><strong>City</strong></td>

</tr>

<?php

$count=1;

while($rows=mysql_fetch_array($result)){

?>

<tr>

<td align="center" bgcolor="#FFFFFF"><input name= "checkbox[]; ?>" type="checkbox" id="checkbox[]" value="<? echo $rows['UID']; ?>"></td>

<td bgcolor="#FFFFFF"><?php echo $rows['UID']; ?></td>

<td bgcolor="#FFFFFF"><?php echo $rows['Name']; ?></td>

<td bgcolor="#FFFFFF"><?php echo $rows['age']; ?></td>

<td bgcolor="#FFFFFF"><?php echo $rows['city']; ?></td>

</tr>

<?php

$count++;

}

?>

<tr>

<td colspan="5" align="center" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete" value="Delete"></td>

</tr>

<?php

// Check if delete button active, start this

if($_POST['delete']){

for($i=0;$i<$count;$i++){

$del_id = $_POST['checkbox[$i]'];

$sql = "DELETE FROM studentrec 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=xyz.php\">";

}

}

mysql_close();

?>

 

</table>

</form>

</td>

</tr>

</table>

 

Link to comment
https://forums.phpfreaks.com/topic/139031-solved-multiple-delete/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.