Advertisement
Guest User

Untitled

a guest
Nov 30th, 2017
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.96 KB | None | 0 0
  1. <?php
  2. $servername = "cs-sql2014.ua-net.ua.edu";
  3. $username = "etkeats";
  4. $password = "11494725";
  5.  
  6. $conn = mysqli_connect($servername, $username, $password, 'etkeats');
  7.  
  8. if ($conn->connect_error) {
  9.   die("Connection failed: " . $conn->connect_error);
  10. }
  11.  
  12. echo "Connected successfully <br>";
  13. ?>
  14.  
  15. <form method="post" action="index.php">
  16.   Input: <input type="text" name="theInput" placeholder="student, teacher, course, textbook, department, or enrolled_in">
  17.   <button type="submit">Submit </button>
  18. </form>
  19.  
  20. <?php
  21. $sql = "select * from ".$_POST["theInput"];
  22. $result = mysqli_query($conn, $sql);
  23. ?>
  24.  
  25. <table>
  26.   <tr>
  27.     <?php
  28.     $headers = mysqli_fetch_fields($result);
  29.     foreach($headers as $header) {
  30.       echo "<th>" . $header->name . "</th>";
  31.     }
  32.     ?>
  33.   </tr>
  34.   <?php
  35.   while($row = mysqli_fetch_assoc($result)) {
  36.     echo "<tr>";
  37.     foreach( $row as $col) {
  38.       echo "<td>" . $col . "</td>";
  39.     }
  40.     echo "</tr>";
  41.   }
  42.   ?>
  43. </table>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement