0

我已经到处搜索这个功能,但我不知道如何做到这一点。我正在尝试使用更新方法来完成此操作,但我总是收到错误“未定义的变量:借用_id”,但我已经清楚地识别了表中的变量。

如果我删除了 borrow_id 变量,该代码就可以工作,但它只会更新表的第一行。我希望这是有道理的..

下面是我正在处理的代码。

<form name="form1" method="post" action="" onSubmit="return validate();">
<table border="1" cellpadding="3" cellspacing="1" align="center">
<tr>
</tr>
<tr>
<td></td>
<td><strong>Borrow ID</strong></td>
<td><strong>Book Title</strong></td>
<td><strong>Date Borrowed</strong></td>
<td><strong>Duration</strong></td>
<td><strong>Overdue</strong></td>
<td><strong>Renewed</strong></td>
<td><strong>Student ID</strong></td>
</tr>

<?php
while($rows=mysql_fetch_array($result)){
?>

<tr>
<td><input name="checkbox[]" type="checkbox" id="checkbox[]" 
value="<?php echo $rows['borrow_id']; ?>"></td>
<td><?php echo $rows['borrow_id']; ?></td>
<td><?php echo $rows['book_title']; ?></td>
<td><?php echo $rows['date']; ?></td>
<td><?php echo $rows['duration']; ?></td>
<td><?php echo $rows['overdue']; ?></td>
<td><?php echo $rows['renewed']; ?></td>
<td><?php echo $rows['stu_id']; ?></td>

</tr>

<?php
}
?>

<tr>
<td align="center" colspan="11"><input name="renew" type="submit" id="renew" value="Renew"></td>
</tr>

<?php

// Check if checked button is active, start 
if(isset($_POST['renew'])){
for($i=0;$i<count($_POST['checkbox']);$i++){
$renew_borrow=$_POST['checkbox'][$i];

$sql = "UPDATE borrow SET date='2014-05-1', duration='14 days', overdue='No', renewed='Yes' WHERE borrow_id=$borrow_id LIMIT 1";

$result = mysql_query($sql);
}

// if it is successful it would redirect to renewstu.php
if($result)
{
echo "<meta http-equiv=\"refresh\" content=\"0;URL=renewstu.php\">";
}
}
mysql_close();
?>

</table>
</form><br />

<div align="center">
<form name='formdel' id="formdel" method='post' action='admin.html'>
    <input type='submit' value='Cancel' />
</form>
4

1 回答 1

2

尝试编辑这行代码,

$renew_borrow=$_POST['checkbox'][$i];

$borrow_id=$_POST['checkbox'][$i];
于 2014-04-17T01:47:59.583 回答