Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
190 views
in Technique[技术] by (71.8m points)

php - Data from database not appearing in table on HTML site

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.

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:_

<?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
", mysqli_connect_error());
  exit();
}
?>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...