数据库中的数据没有出现在HTML网站的表格中 [英] Data from database not appearing in table on HTML site

查看:78
本文介绍了数据库中的数据没有出现在HTML网站的表格中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在访客名单的联系人中有一个表格。在提交按钮被键入后的同一页面上,我想检索数据并显示客人列表。键入表单的数据在数据库中被接收。但是他们没有在我的屏幕上显示在HTML网站上。

I have a form that keys in the contacts of the guest list. On the same page itself after the submit button is keyed I want to retrieve the data and display the list of guest. The data keyed into the form is received in the database. But they are not being displayed on my screen on the HTML site.

顶部我的invites.HTML:

top of my 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:_

_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();
}
?>


推荐答案

首先,您不需要重复
包括(guestlist_connect.php);
你也忘了结束循环

First, you do not need to repeat include("guestlist_connect.php"); And also you forgot to end while loop

  <?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 
    $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 } ?> // you forgot to end a while loop
    </tbody> </table> 
    <?php mysql_close($connector); ?> 
    </div><!--End Rightcontainer--> </div>

这篇关于数据库中的数据没有出现在HTML网站的表格中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆