Guest User

Untitled

a guest
Mar 16th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.24 KB | None | 0 0
  1. <?php
  2. //Set up all this stupid business
  3.  
  4.   $host="localhost"; // Host name
  5.   $username = "dnieto"; // Mysql username
  6.   $password = ""; // Mysql password
  7.   $db_name = "csci4970_fall11_team1_dev"; // Database name
  8.   $tbl_name = "books_approved"; // Table name
  9.  
  10. // Connect to server and select databse.
  11. mysql_connect("$host", "$username", "$password")or die("cannot connect");
  12. mysql_select_db("$db_name")or die("cannot select DB");
  13.  
  14. //This gets hte title of the book from the value we submitted as 'booktitle'
  15. // hence GET['booktitle]
  16. $booktitle = $_GET['booktitle'];
  17.  
  18. //where the SQL statement goes, easy enough
  19. $sql = "SELECT * FROM $tbl_name WHERE ISDN = '$booktitle'";
  20.  
  21. //store the result in a variable
  22. $result=mysql_query($sql);
  23.  
  24. //count to see if there is results
  25. $count=mysql_num_rows($result);
  26.  
  27. //if there are any books find create the table, this is easily modified to look nicer
  28. //just proof of concept
  29. if($count > 0)
  30. {
  31.     echo '<table>';
  32.     while($row = mysql_fetch_array($result))
  33.     {
  34.         echo '<tr>';
  35.         echo "<td>" . $row['Title'] . "</td><td>" . $row['Professor'] . "</td>";
  36.         echo '</tr>';
  37.     }
  38.     echo '</table>';
  39. }
  40. //otherwise no books found etc
  41. else
  42. {
  43.     echo "ham sandwhich";
  44. }
  45.  
  46. ?>
Add Comment
Please, Sign In to add comment