下面是我创建的用来显示数据库中两行信息的php页面和代码。

<?php
$sql = "SELECT * from events;";
$result = mysqli_query($conn, $sql);
$resultCheck = mysqli_num_rows($result);
if($resultCheck > 0) {
while($row = mysqli_fetch_assoc($result)) {
echo '
<div class="full border" id="border">
<p>
<img src="event.jpg" alt=" " id="event1"/>
<h1>'.$row['EVENT_NAME'].'</h1>
<a>'.$row['EVENT_DESC'].'</a>
<p align="right">
<form action="booking.php" method="get">
<input type="hidden" name="eventId" value="$eventId">
<button type="submit" class="button">More information</button>
</form>
</p>
</p>
</div>
<br/><br/>
';
}
}
?>这是我的数据库的图片。

这是用户单击“更多信息”按钮后将被重定向到的代码和页面。

<?php
$sql = "SELECT * from events;";
$result = mysqli_query($conn, $sql);
$resultCheck = mysqli_num_rows($result);
if($resultCheck > 0) {
while($row = mysqli_fetch_assoc($result)){
echo '
<h1>'.$row['EVENT_NAME'].'</h1>
<tr>
<td><h5>Venue</h5></td>
<td><h5>Date</h5></td>
<td><h5>Time</h5></td>
<td><h5>Joining Price</h5></td>
<td><h5>Seats left</h5></td>
</tr>
<tr>
<td><h5>'.$row['EVENT_VENUE'].'</h5></td>
<td><h5>'.$row['START_DATE'].' - '.$row['END_DATE'].'</h5></td>
<td><h5>'.$row['START_TIME'].'-'.$row['END_TIME'].'</h5></td>
<td><h5>'.$row['TICKET_PRICE'].'</h5></td>
<td><h5>'.$row['SEATS_AVAILABILITY'].'</h5></td>
</tr>
</table>
</p>
<form id="form" style="font-size: 15px;">
<fieldset class="form">
<legend>Please fill this form:</legend>
<label for="name">Enter your name (same as IC) : </label>
<input type="text" class="a" id="name"></br><br>
<label for="studentId">Enter your student ID : </label>
<input type="text" class="a" id="studentId"></br></br>
<label for="email">Enter your email: </label>
<input type="text" class="a" id="email"></br></br>
<label for="phoneNumber">Enter your phone number: </label>
<input type="number" class="a" id="phoneNumber"></br></br>
Select your preferred payment method:</br>
<input type="radio" id="type1" name="payment" value="eWallet">
<label for="type1">E-wallet</label></br>
<input type="radio" id="type2" name="payment" value="onlineBanking">
<label for="type2">Online banking</label></br>
<input type="radio" id="type3" name="payment" value="creditCard">
<label for="type3">Credit card</label></br></br>
<button type="button" onclick="window.location.href="records.php"">Submit</button>
</fieldset>
</form>
<div style="padding: 10px;margin-left: 20%; margin-right: 20%; border: 1px dotted black;">
<h3 align="center">Terms and conditions: </h3>
<p align="left">
'.$row['TERMS'].'
</p>
</div>
';
}
}
?>我实际上想做的是让预订页面通过从数据库中获取数据来显示表格中的正确信息和每个事件的“条款和条件”。我尝试了几种方法,但似乎都不起作用。
发布于 2021-08-30 14:19:00
在创建按钮的位置进行所需的更改。
<input type="hidden" name="eventId" value="'.$row['EVENT_ID'].'">上面的代码将使用数据库中的EVENT_ID字段设置隐藏字段的值。在下一个php页面中使用此eventId从数据库中提取确切的(单个)行。
$eid = $_POST["eventId"];
$eid = addslashes($eid);
$sql = "SELECT * from events WHERE `EVENT_ID`='".$eid."';";使用上面的sql,您将获得与EVENT_ID对应的数据。删除while循环,并使用获取的数据填充字段。
https://stackoverflow.com/questions/68985473
复制相似问题