我有一個表格,它是來賓列表的聯繫人中的鍵。在提交按鈕被鍵入後的同一頁面上,我想檢索數據並顯示客人列表。鍵入表單的數據在數據庫中被接收。但是他們沒有在我的屏幕上顯示在HTML網站上。來自數據庫的數據沒有出現在HTML網站的表格中
頂我invites.HTML的:
<?php
include("guestlist.php");
include("guestlist_connect.php");
?>
invites.HTML:
<h2 >Invites & Guest List</h2>
<table border="2">
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Contact</th>
<th>Invitation</th>
</tr>
</thead>
<tbody>
<?php
include("guestlist_connect.php");
$result = mysql_query("SELECT * FROM guestlist");
while($row = mysql_fetch_assoc($result)){
?>
<tr>
<td><? php echo $row["fname"]; ?></td>
<td><? php echo $row["lname"]; ?></td>
<td><? php echo $row["email"]; ?></td>
<td><? php echo $row["contact"]; ?></td>
</tr>
<?php
</tbody>
</table>
<?php mysql_close($connector); ?>
</div><!--End Rightcontainer-->
</div>
_guestlist_connect.php:_
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "registration";
$conn = mysqli_connect($servername, $username, $password, $dbname) or
die("Connection failed: " . mysqli_connect_error());
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
?>
嘗試調試:的var_dump($結果);或print_r($ result);正在查詢。 –
'<? php'是錯誤的。它必須是'<?php'。此外,mysql_ *函數已被棄用,並且不再支持PHP7。所以切換到PDO或mysqli_ * –
您只需要連接到數據庫一次 – RiggsFolly