当用户单击批准或删除时,我希望代码更新数据库中的相应行。请帮我。
下面是循环表。
<table id="employee_data" class="table table-striped table-bordered">
<thead>
<tr>
<td>ID</td>
<td>Name</td>
<td>Position</td>
<td></td>
</tr>
</thead>
<?php
while($row = mysqli_fetch_array($result))
{ ?>
<tr>
<td><?php echo $row["request_id"];?></td>
<td><?php echo $row["name"]; ?></td>
<td><?php echo $row["title"]?></td>
<td><button type="submit" name="approve" data-approve="<?php echo $row["request_id"]; ?>" value="toapprove" onclick="yourEvent(this);">approve</button></td>
<?php
}
?>
这是Javascript和PHP代码。
<?php
$rID = '<script>
function yourEvent(decision)
{
var requestID = decision.getAttribute("data-approve");
document.writeln(requestID);
}
</script>';
//echo $rID;
if ($rID) {
$sql = "UPDATE requisition SET status='1' WHERE request_id= '$rID'";
$query = mysqli_query($connect, $sql);
if ($query) {
echo "database updated";
}
}
?>