Supposed to have fetch data from a database, and display on a table. On every record is a text box where one can insert a receipt number and submit. On submit, the receipt number should be inserted on a database for that record and the page reloads displaying the inserted record instead of a text field. I'm not sure what I;m doing wrong because the page loads to a blank page.
$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');
}