开发者

How to delete data from database by using radio button in php?

开发者 https://www.devze.com 2023-03-01 03:02 出处:网络
Actually here is the main problem. It does not get the value of \"$radio[$i]\" statement that can be used as a condition here. So will anyone please tell me what I have to write there instead of \"$ra

Actually here is the main problem. It does not get the value of "$radio[$i]" statement that can be used as a condition here. So will anyone please tell me what I have to write there instead of "$radio[$i]" as the output will come.

<?php
if(isset($_POST['delete']))
{
 开发者_JAVA技巧   for($i=0;$i<$count;$i++)
    {
        $del_id = $radio[$i];
        $sql = "DELETE FROM reigster WHERE id='".mysql_real_escape_string($del_id)."'";
        $result = mysql_query($sql);
    }
    if($result)
    {
        echo "<meta http-equiv=\"refresh\" content=\"0;URL=delete_multiple.php\">";
    }
}
mysql_close();
?>


After looking to your previous question The problem is in this code of block

for($i=0;$i<$count;$i++)
 {
 $del_id = $radio[$i];
 $sql = "DELETE FROM reigster WHERE id='".mysql_real_escape_string($del_id)."'";
 $result = mysql_query($sql);
 }

Replace above with this code

     $count=count($_POST['radio']); 
     for($i=0;$i<$count;$i++)
     {
       $del_id = $_POST['radio'][$i];
       $sql = "DELETE FROM reigster WHERE id='".mysql_real_escape_string($del_id)."'";
       $result = mysql_query($sql);
     }


 foreach($_POST['radio'] as $del_id)
 {
   $sql = "DELETE FROM reigster WHERE id='".mysql_real_escape_string($del_id)."'";
   $result = mysql_query($sql);
 }


Try this

if(isset($_POST['delete']))
{
    for($i=0;$i<$count;$i++)
    {
        $del_id = $radio['checked'];
        $sql = "DELETE FROM reigster WHERE id='".mysql_real_escape_string($del_id)."'";
        $result = mysql_query($sql);
    }
    if($result)
    {
        echo "<meta http-equiv=\"refresh\" content=\"0;URL=delete_multiple.
0

精彩评论

暂无评论...
验证码 换一张
取 消