Advertisement
Guest User

Untitled

a guest
Apr 18th, 2017
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.82 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. <?php
  6.   $servername = "localhost";
  7.   $username = "username";
  8.   $password = "password";
  9.   $dbname = "myDB";
  10.  
  11.   // Create connection
  12.   $conn = new mysqli($servername, $username, $password, $dbname);
  13.   // Check connection
  14.   if ($conn->connect_error) {
  15.       die("Connection failed: " . $conn->connect_error);
  16.   }
  17.  
  18.   $sql = "SELECT id, firstname, lastname FROM MyGuests";
  19.   $result = $conn->query($sql);
  20.  
  21.   if ($result->num_rows > 0) {
  22.       echo "<table><tr><th>ID</th><th>Name</th></tr>";
  23.       // output data of each row
  24.       while($row = $result->fetch_assoc()) {
  25.           echo "<tr><td>". $row["id"]. "</td><td>". $row["firstname"]. "</td><td>" . $row["lastname"] . "</td></tr>";
  26.       }
  27.   } else {
  28.       echo "0 results";
  29.   }
  30.  
  31.   $conn->close();
  32. ?>  
  33.  
  34. </body>
  35. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement