我正在尝试访问我的数据库,并创建一个交易仍处于待定状态,接受,拒绝,消费或付款的复选框。我已经从数据库访问它并在复选框中打印出来。现在的问题是我很难更改复选框的值,例如当授权用户批准了交易时(通过选中已批准列的复选框),待处理的复选框将自动取消选中并自动成为保存。当交易被拒绝时也是如此。
这是我的代码。有人可以帮我解决这个问题吗?
<!DOCTYPE HTML>
<html>
<head>
<title> Pending Requests </title>
</head>
<body>
<?php
session_start();
$myusername = $_SESSION['idNumber'];
if ($_SESSION['login'] == false) {
echo "<script>alert('Login your account first');
window.location.href='http://localhost/loginPage.php';</script>";
} else {
session_start();
$myBranch = $_SESSION['branch'];
$myIdNumber = $_SESSION['id_number'];
$username = "formtemplate";
$password = "admin123";
$hostname = "localhost";
$dbhandle = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL");
$selected = mysql_select_db("practice", $dbhandle) or die("Could not select examples");
$queryBranch = mysql_query("SELECT fname, lname FROM trial where department = '$myBranch'");
$total2 = mysql_num_rows($queryBranch);
$counter = 0;
while ($row = mysql_fetch_assoc($queryBranch)) {
$fname = $row['fname'];
$lname = $row['lname'];
$fullName[$counter] = $fname . " " . $lname;
//echo "<option value = '".$fullName."'>".$fullName."</option>";
$counter++;
}
echo '<form method = "post">
<select style="font-size:20px" name = "empList" length = "10">';
// echo "The first name is ". $fname;
for ($a = 0; $a < $total2; $a++) {
echo "<option value = '" . $fullName[$a] . "'>" . $fullName[$a] . "</option>";
}
echo ' </select>
<br><input type ="submit" name = "submit" value = "select">
</form>';
$fullnameHolder = $_POST['empList'];
if ($_POST['submit'] and $_SERVER['REQUEST_METHOD'] == "POST") {
echo "You selected " . $fullnameHolder;
$query = mysql_query("SELECT * FROM t where name = '$fullnameHolder'");
$total = mysql_num_rows($query);
$counter = 0;
while ($row = mysql_fetch_assoc($query)) {
//just add the all required data. This is only the practice
$transNum[$counter] = $row['number'];
$transactions[$counter] = $row['transaction'];
$name[$counter] = $row['name'];
$branchs[$counter] = $row['branch'];
$dateIn[$counter] = $row['dateIn'];
$dateOut[$counter] = $row['dateOut'];
$pending[$counter] = $row['pending'];
$approve[$counter] = $row['approve'];
$decline[$counter] = $row['decline'];
$consume[$counter] = $row['consume'];
$paid[$counter] = $row['paid'];
$counter++;
}
echo '<form method = "post">
<table border = "1">
<tr>
<th> Transaction number</th>
<th> Transaction</th>
<th> Name </th>
<th> Branch </th>
<th> Date From </th>
<th> Date to </th>
<th> Pending </th>
<th> Approve </th>
<th> Decline </th>
<th> Consume </th>
<th> Paid </th>
</tr>';
for ($z = 0; $z < $total; $z++) {
echo '<tr>
<td>' . $transNum[$z] . ' </td>
<td>' . $transactions[$z] . '</td>
<td>' . $name[$z] . '</td>
<td>' . $branchs[$z] . '</td>
<td>' . $dateIn[$z] . '</td>
<td>' . $dateOut[$z] . '</td>
<td>' . '<input type="checkbox" name="sss[]" value="A"' . (($pending[$z] == "yes") ? "checked='checked'" : "") . '>' . '</td>
<td>' .
'<input type="checkbox" name="ss" value="A"' . (($approve[$z] == "yes") ? "checked='checked'" : "") . '>' . '</td>
<td>' .
'<input type="checkbox" name="ss" value="A"' . (($decline[$z] == "yes") ? "checked='checked'" : "") . '>' . '</td>
<td>' . '<input type="checkbox" name="ss" value="A"' . (($consume[$z] == "yes") ? "checked='checked'" : "") . '>' . '</td>
<td>' . '<input type="checkbox" name="ss" value="A"' . (($paid[$z] == "yes") ? "checked='checked'" : "") . '>' . '</td>
</tr>';
}
echo ' </table>
</form>';
}
}
?>
</body>
</html>