我创建了一个约会表,其中user1将添加约会,user2将接受/拒绝约会。 现在我的问题是当点击接受和拒绝时它会显示在表格中但是没有在数据库中更新我对此做了很多研究但是在路障后遇到了路障,所以我真的希望你的帮助,非常感谢!
这是我的代码:
<table cellpadding="0" cellspacing="0" border="0" class="table table-condensed" id="example">
<thead>
<tr>
<th>appoinment ID</th>
<th>Date</th>
<th>time</th>
<th>teacher</th>
<th>parent</th>
<th> accept/reject </th>
<th>state</th>
</tr>
</thead>
<tbody>
<?php
$query=mysqli_query($conn, "select * from `app` left join `par` on par.par_id=app.par_id
left join `tea` on tea.tea_id=app.tea_id
ORDER BY app_id DESC");
if($query === false)
{
throw new Exception(mysqli_error($conn));
}
while($row=mysqli_fetch_array($query))
{
$ann_id=$row['app_id'];
$date=$row['date'];
$msg=$row['time'];
$username = $row['username'];
$username = $row['p_username'];
?>
<tr>
<td><?php echo $row['app_id'] ?></td>
<td> <?php echo date('j/m/y',strtotime($row['date'])); ?></td>
<td><?php echo $row['time'] ?></td>
<td><?php echo $row['p_username'] ?></td>
<td><?php echo $row['username'] ?></td>
<td>
<a href="#" class="reject">reject</a>
<a href="#" class="accept">accept</a>
</td>
<td>
<div class="chgtext">PENDING</div>
</td>
</tr>
<?php
if (isset($_GET['state'], $_GET['app_id'])) {
$stmt = mysqli_prepare($conn, "UPDATE app SET state = ? WHERE app_id = ?");
mysqli_stmt_bind_param($stmt, "sd", $_GET['state'], $_GET['s.app_id']);
$stmt->execute();
$stmt->close();
}
}
?>
</tbody>
</table>
</div>
</form>
答案 0 :(得分:1)
你有错误。您正在使用$_GET
请求并将其设置为url。更改您的html标签,如下所示
<a href="tea_appview.php?app_id=<?php echo $row['app_id'] . "&" . "state=reject";?>" class="reject">reject</a>
<a href="tea_appview.php?app_id=<?php echo $row['app_id'] . "&" . "state=accept";?>" class="reject">accept</a> <!-- I assumed that column names in database were app_id and state
在PHP代码中
if (isset($_GET['state'], $_GET['app_id'])) {
$stmt = mysqli_prepare($conn, "UPDATE app SET state = ? WHERE app_id = ?");
mysqli_stmt_bind_param($stmt, "sd", $_GET['state'], $_GET['app_id']);
$stmt->execute();
$stmt->close();
}
}
我希望它会对你有所帮助。如果有任何问题,请告诉我