Delete values selected using checkbox
I want to delete values that has been selected using checkbox. I am using this script though its not giving any error but its not working
please help it out.
for checkbox
<input name="checkbox[]" type="checkbox" value="<?=$row['s_id']?>">
for delete button
<input type="submit" name="delete" value="Delete">
for query
if(isset($_POST['delete']))
{
$count=array();
$count=$_POST['checkbox'];
for($i=0;$i<count($count);$i++){
开发者_如何学JAVA $del_id = $checkbox['$i'];
$sql = "DELETE FROM t_s_list WHERE s_id='$del_id'";
$result = mysql_query($sql);
}
$NEW="Selected records Deleted";
}
var_dump($_POST['checkbox']);
var_dump($count);
Check the name of your delete button. $_POST['delete']
needs the name to be 'delete'.
Also please check $del_id = $checkbox['$i'];
It should be $del_id = $checkbox[$i]
;
And for security sake
$sql = "DELETE FROM t_s_list WHERE s_id='".mysql_real_escape_string($del_id)."'";
You write:
<input type="submit" name="Submit" value="Delete">
but
$_POST['delete']
Use var_dump($_POST)
to see what the issue is here, if you don't see it.
Also, where is your SQL Injection protection?
精彩评论