douwojiao5919 2015-07-14 07:18
浏览 88

PHP MySQL多个复选框更新记录

In need of help, I'm trying to multiple update using checkbox.

Here is my Query

PHPUpdateCheckBox.php

<?php
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("database");

    for($i=0;$i<count($_POST["chkSub"]);$i++)
    {
        if($_POST["chkSub"][$i] != "")
        {
            $strSQL = "UPDATE example_db
                       SET submitted = 'Y'  
                       WHERE exp_hdr_no = '".$_POST["chkSub"][$i]."' ";
            $objQuery = mysql_query($strSQL);
        }
    }

    echo "Record Updated.";

mysql_close($objConnect);
?>

Here is my website

<html>
<head>
<title>HEADER</title>
</head>
<body>
<script language="JavaScript">
    function ClickCheckAll(vol)
    {

        var i=1;
        for(i=1;i<=document.frmMain.hdnCount.value;i++)
        {
            if(vol.checked == true)
            {
                eval("document.frmMain.chkSub"+i+".checked=true");
            }
            else
            {
                eval("document.frmMain.chkSub"+i+".checked=false");
            }
        }
    }

    function onUpdate()
    {
        if(confirm('Do you want to Submit?')==true)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
</script>
<form name="frmMain" action="PHPUpdateCheckBox.php" method="post" OnSubmit="return onUpdate();">
<?php
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("database");
$strSQL = "SELECT * FROM expample_db";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<table width="600" border="1">
  <tr>
    <th width="91"><a href="<?php echo $_SERVER["PHP_SELF"];?>?sort=exp_hdr_no&order=<?php echo $strNewOrder?>"> <div align="center">Header No </div></th>
    <th width="98"><a href="<?php echo $_SERVER["PHP_SELF"];?>?sort=cust_name&order=<?php echo $strNewOrder?>"> <div align="center">Customer Name </div></th>
    <th width="97"><a href="<?php echo $_SERVER["PHP_SELF"];?>?sort=time_in&order=<?php echo $strNewOrder?>"> <div align="center">Time In</div></th>
    <th width="59"><a href="<?php echo $_SERVER["PHP_SELF"];?>?sort=time_out&order=<?php echo $strNewOrder?>"> <div align="center">Time Out </div></th>
    <th width="71"><a href="<?php echo $_SERVER["PHP_SELF"];?>?sort=ref_type_code&order=<?php echo $strNewOrder?>"> <div align="center">Ref Type Code </div></th>
    <th width="59"><a href="<?php echo $_SERVER["PHP_SELF"];?>?sort=ref_no&order=<?php echo $strNewOrder?>"> <div align="center">Ref No </div></th>
    <th>
        Submitted
      <input name="CheckAll" type="checkbox" id="CheckAll" value="Y" onClick="ClickCheckAll(this);">
    </div></th>
  </tr>
<?php
$i = 0;
while($objResult = mysql_fetch_array($objQuery))
{
$i++;
?>
  <tr>
   <td><div align="center"><div align="center"><?php echo $objResult["exp_hdr_no"];?></div></td>
    <td><?php echo $objResult["cust_name"];?></td>
    <td align="right"><?php echo $objResult["time_in"];?></td>
    <td align="right"><?php echo $objResult["time_out"];?></td>
    <td><?php echo $objResult["ref_type_desc"];?></td>
    <td><?php echo $objResult["ref_no"];?></td>
    <td align="center"><input type="checkbox" name="chkSub[]" id="chkSub<?php echo $i;?>" value="<?php echo $objResult["submitted"];?>"></td>
  </tr>
<?php
}
?>
</table>
<?php
mysql_close($objConnect);
?>
<input type="submit" name="btnSubmit" value="Submit">
<input type="hidden" name="hdnCount" value="<?php echo $i;?>">
</form>
</body>
</html>

Example of Site enter image description here

I'm trying to update the 'Submitted' Column only, if someone can help me, thanks!

Thank you! :)

  • 写回答

1条回答 默认 最新

  • douye5949 2015-07-14 07:25
    关注

    You did not put the key in WHERE condition

    change

    WHERE '".$_POST["chkSub"][$i]."' 
    

    to

    WHERE `col_name` = '".$_POST["chkSub"][$i]."'
    
    评论

报告相同问题?

悬赏问题

  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题