【问题标题】:Renewing a library book through a checkbox in php通过php中的复选框更新图书馆书籍
【发布时间】:2014-04-17 01:40:26
【问题描述】:

我已经到处寻找这个功能,但我不知道如何做到这一点。我正在尝试使用更新方法来完成此操作,但我总是收到错误“未定义的变量:借用_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>

【问题讨论】:

    标签: php html renewal


    【解决方案1】:

    尝试编辑这行代码,

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

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

    【讨论】:

      猜你喜欢
      • 2022-01-16
      • 2019-05-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-10
      • 2016-02-05
      • 2022-07-20
      • 2015-01-20
      相关资源
      最近更新 更多