0
我试图一次更新十二行。我搜索了不同的方式来做这件事,但他们都没有和我一起工作。按“提交”时,我看不到任何动作发生。任何人都可以帮我找到下面的脚本中有什么错:使用一种形式更新多行
<?php
include 'connection.php';
$sql="SELECT * FROM tbl_maint_track1";
$result=mysql_query($sql);
// Count table rows
$count=mysql_num_rows($result);
$sno = array();
?>
<table width="500" border="0" cellspacing="1" cellpadding="0">
<form name="form1" method="post" action="">
<tr>
<td>
<table width="500" border="0" cellspacing="1" cellpadding="0">
<tr>
<td align="center"><strong>S No</strong></td>
<td align="center"><strong>Qty</strong></td>
<td align="center"><strong>Maint Catgry</strong></td>
<td align="center"><strong>Uprice</strong></td>
<td align="center"><strong>Tprice</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td align="center"><? $sno[]=$rows['sno']; ?><? echo $rows['sno']; ?></td>
<td align="center"><input name="qty[]" type="text" id="qty" value="<? echo $rows['qty']; ?>"></td>
<td align="center"><input name="maint_catgry[]" type="text" id="maint_catgry" value="<? echo $rows['maint_catgry']; ?>"></td>
<td align="center"><input name="uprice[]" type="text" id="uprice" value="<? echo $rows['uprice']; ?>"></td>
<td align="center"><input name="tprice[]" type="text" id="tprice" value="<? echo $rows['tprice']; ?>"></td>
</tr>
<?php
}
?>
<tr>
<td colspan="4" align="center"><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</td>
</tr>
</form>
</table>
<?php
$sno = $_POST['sno'];
$qty = $_POST['qty'];
$maint_catgry = $_POST['maint_catgry'];
$uprice = $_POST['uprice'];
$tprice = $_POST['tprice'];
// Check if button name "Submit" is active, do this
if(isset($_POST["$Submit"])){
for($i=0;$i<$count;$i++){
$sql1= "UPDATE tbl_maint_track1 SET qty = '{$qty[$i]}', maint_catgry = '{$maint_catgry[$i]}', uprice = '{$uprice[$i]}', tprice = '{$tprice[$i]}' WHERE sno = '{$sno[$i]}' ";
$result1=mysql_query($sql1);
}
}
if($result1){
echo "Thanks, $count records updated";
}
else
{
echo "No record updated";
}
close_conn();
?>
有没有更好的方法来更新多个记录与一种形式?
在此先感谢。
谢谢大卫的答复。一旦解决了其他问题,我将使用mysql_real_escape_string。正如你所建议的那样,我已经将[$ i]放入循环中,但是它仍然不会将更改传递给表。还有什么可以阻止数据传输的形成? –
也许尝试使用更新的语法,而不是使用刚才使用的{}语法。运算符加入字符串。 – davidethell
我用上面的语法更新查询,但它仍然不起作用。任何其他建议? –