表单由打印出所有等待批准的行的函数组成;
function all_reviews(){
$query1= mysql_query("SELECT * FROM {$table} WHERE first != '' && disp_state= '0' && rejected != '1'");
if (!$query1) {
die("Query to show fields from table failed");
}
$fields_num = mysql_num_fields($query1);
// printing table rows
while($row = mysql_fetch_array($query1))
{
//review action buttons
echo "<div class=\"rev_action\">";
echo "<input type=\"hidden\" name=\"".$row['id']."\">";
echo "<input type=\"submit\" name=\"accept\" value=\"Approve\" class=\"success rev_button\" onclick=\"document.getElementById('review_action').submit()\">";
echo "<input type=\"submit\" name=\"reject\" value=\"Reject\" class=\"error rev_button\" onclick=\"document.getElementById('review_action').submit()\">";
echo "</div>";
}
我猜正确的方法是在隐藏的输入中打印行 ID。问题是,一次可能有超过 1 行打印出来。
如何选择与批准或拒绝按钮相关的确切行?
html:
<form name="form" action="include/review_submit.php" id="review_action" method="post">
<?php all_reviews(); ?>
</form>
php (review_submit.php):
//database server connection
mysql_connect ("$servername","$dbusername","$dbpassword") or die(mysql_error());
//database connection
mysql_select_db("esd_db") or die(mysql_error());
//data feilds from review form
if($_POST['button'] == "Approve") {
//code to update given row with an approval status
}
//data feilds from review form
if($_POST['button'] == "Reject") {
//code to update given row with an rejection status
}
//insert values into table
mysql_query("UPDATE `reviews` ") or die(mysql_error());
Print "Success";
?>