-1

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\n", mysqli_connect_error());
  exit();
}
?>
halfer
  • 19,824
  • 17
  • 99
  • 186
alexvin
  • 41
  • 7
  • try to debug with: var_dump($result); or print_r($result); just under query. – Sergiu Costas Sep 12 '17 at 11:23
  • 2
    ` php` is wrong. It has to be ` – Joshua K Sep 12 '17 at 11:23
  • You only need to connect to the database Once – RiggsFolly Sep 12 '17 at 11:25
  • 1
    Every time you use [the `mysql_`](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) database extension in new code **[this happens](https://media.giphy.com/media/kg9t6wEQKV7u8/giphy.gif)** it is deprecated and has been for years and is gone for ever in PHP7. If you are just learning PHP, spend your energies learning the `PDO` or `mysqli` database extensions and prepared statements. [Start here](http://php.net/manual/en/book.pdo.php) – RiggsFolly Sep 12 '17 at 11:25
  • in guestlist_connect you're using mysqli_* functions to connect to the database. but later on you're using mysql functions. THAT's oine of your problems. – Joshua K Sep 12 '17 at 11:28
  • 1
    a while with an else-condition? I would say... learn the basics! The code is more broken than anything else. Read the tutorial you're working on from the beginning again! – Joshua K Sep 12 '17 at 11:30
  • unless it's a typo or this is a partial cut of the page, your while loop does not end before the end of the `tbody` and there's a php opening tag with no closing tag, and two closing `div` tags without opening ones. It _looks_ totally broken, but we don't know if this is actually representative of your real code or not. – ADyson Sep 12 '17 at 13:18
  • Also why do you include guestlist_connect twice? Very unnecessary. And as already mentioned you're mixing database libraries, including one which is discontinued. You should be getting errors all over the place. If PHP error reporting isn't turned on, you should turn it on to make your development process easier. – ADyson Sep 12 '17 at 13:19

1 Answers1

-1

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>
Hamis Hamis
  • 84
  • 2
  • 9