drhwb470572 2011-10-20 19:52
浏览 69
已采纳

删除多行函数中的未定义变量和索引

Edit:I added this

if (isset($_POST['delete']) && isset($_POST['checkbox'])) (get from an answer below but it seems the asnwer is gone)

and now the undefined varialbe and index error are gone...but the problem now is when I try to delete , it require check and click delete button twice to delete the selected rows...

  <form name="frmSearch" method="post" action="insert-add.php">

<table width="600" border="1">
  <tr>
    <th width="50"> <div align="center">#</div></th>
    <th width="91"> <div align="center">ID </div></th>
    <th width="198"> <div align="center">First Name </div></th>
    <th width="198"> <div align="center">Last Name </div></th>
    <th width="250"> <div align="center">Mobile Company </div></th>
    <th width="100"> <div align="center">Cell </div></th>
    <th width="100"> <div align="center">Workphone </div></th>
    <th width="100"> <div align="center">Group </div></th>
  </tr>
    </form>
<?

    echo "<form name='form1' method='post' action=''>";

while($objResult = mysql_fetch_array($objQuery))
{


    echo "<tr>";
    echo "<td align='center'><input name=\"checkbox[]\" type=\"checkbox\" id=\"checkbox[]\" value=\"$objResult[addedrec_ID]\"></td>";
    echo "<td>$objResult[addedrec_ID] </td>";
    echo "<td>$objResult[FirstName]</td>";
    echo "<td>$objResult[LastName] </td>";
    echo "<td>$objResult[MobileCompany] </td>";
    echo "<td>$objResult[Cell] </td>";
    echo "<td>$objResult[WorkPhone] </td>";
    echo "<td>$objResult[Custgroup] </td>";

   echo "</tr>";

}


 echo "<td colspan='7' align='center'><input name=\"delete\" type=\"submit\" id=\"delete\" value=\"Delete\">";

 if (isset($_POST['delete']) && isset($_POST['checkbox'])) // from button name="delete"
 {
 $checkbox = ($_POST['checkbox']); //from name="checkbox[]"
     $countCheck = count($_POST['checkbox']);

 for($d=0;$d<$countCheck;$d++)
     {
         $del_id  = $checkbox[$d];

 $sql = "DELETE from UserAddedRecord where addedrec_ID = $del_id";

 $result2=mysql_query($sql)  or trigger_error(mysql_error());;;

     }
         if($result2)
     {  
          $fgmembersite->GetSelfScript();
         }
         else
         {
 echo "Error: ".mysql_error();
         }
 }
  echo "</form>";

Thanks for every reply.

  • 写回答

2条回答 默认 最新

  • dongsheng66783619 2011-10-20 19:57
    关注

    The first notice is due to no $_POST["checkbox"] variable. If you're using AJAX, inspect your query with firebug to check if you're sending a checkbox variable.

    The second undefined is coming from your nesting. See my below example:

    $foo = 0
    if($foo ==1){
        $bar = 5;
    }
    if($bar == 2){
        //Blah
    }
    

    If you were to run that then $bar would never be set, hence the notice. As $countCheck is set to 0 as $_POST["checkbox"] is not set, then the for loop never runs hence $result2 is never set.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作