需要帮助, 我正在尝试使用复选框进行多次更新。
这是我的查询
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);
?>
这是我的网站
<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>
网站示例
我正在尝试更新“已提交”列,如果有人可以帮助我,谢谢!
谢谢! :)
答案 0 :(得分:0)
您没有将密钥放在WHERE条件
中更改
WHERE '".$_POST["chkSub"][$i]."'
到
WHERE `col_name` = '".$_POST["chkSub"][$i]."'