데이터베이스에서 데이터를 가져 와서 표에 표시한다고 가정합니다. 모든 기록에는 영수증 번호를 입력하고 제출할 수있는 텍스트 상자가 있습니다. 제출시 해당 레코드의 데이터베이스에 영수증 번호를 삽입해야하며 텍스트 필드 대신 삽입 된 레코드를 표시하는 페이지가 다시로드됩니다. 나는 내가 뭘 잘못했는지 모르겠다. 왜냐하면 페이지가 빈 페이지로로드되기 때문이다.PHP HTML 표에서 양식 제출
$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');
}
데이터베이스에서 가져온 모든 레코드에 나타납니다. –
데이터베이스에서 가져온 레코드에만 표시되어 이상적으로 각 레코드를 개별적으로 처리 할 수 있어야합니다. –
당신이이 조건에 부합하지 않는 것 같네요. if ($ result-> num_rows> 0) {결과 num 행을 에코하여 해당 조건을 충족하는지 확인하십시오. – Jeff