假设从数据库中获取数据,并显示在表上。在每个记录上都有一个文本框,可以在其中插入收据编号并提交。在提交时,应将收据编号插入该记录的数据库中,并且页面重新加载显示插入的记录而不是文本字段。我不确定我做错了,因为页面加载到空白页面。
$sql = "SELECT * FROM customer";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo " <table><tr><th>ID</th><th>Name</th>
<th>Amount</th><th>TransactionID</th><th>Mobile Number</th>
<th>Time Paid</th><th>Account</th>
<th>Receipt Number</th></tr>";
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<tr><td>" . $row["id"]. "</td>
<td>" . $row["name"]. "</td><td>" . $row["amount"]. "</td>
<td>" . $row["trans_id"]. "</td><td>" . $row["msisdn"]. "</td>
<td>" . $row["time_paid"]. "</td>
<td>" . $row["status"]. "</td>
<td><form action= 'receipt.php' method='post'>
<input type ='text' name='receipt'>
<input type ='hidden' name='hidden' value='".$row["receipt"]."'>
<input type='submit' name='submit' value='submit'></td></form></tr>";
}
echo "</table> ";
// receipt.php
if(isset($_POST['submit']))
{
//connection
$sql = "INSERT INTO customer (receipt, date_entered) VALUES ('" . $_POST['receipt'] . "','NOW()')";
if ($conn->query($sql) === TRUE) {
// echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
header('Location: http://localhost/com/payf.php');
}
else {
echo "Please Enter the Receipt Number";
header('Location: http://localhost/com/payf.php');
}