Advertisement
Guest User

heggie is gay

a guest
Feb 10th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. <?php
  2.  
  3. //assign PHP variables for connection code
  4. $servername="localhost";
  5. $username="root";
  6. $password="";
  7. $database="wildscottrust";
  8.  
  9. //connect to the database server
  10. $link=mysql_connect($servername,$username,$password) ;
  11. if(! $link)
  12. {
  13. die('Connection Failed'.mysql_error());
  14. }
  15.  
  16. //Select Wild Scot Trust database
  17. mysql_select_db($database,$link) ;
  18.  
  19. //Using GET assign PHP details
  20. $Name = $_GET['AnimalName'] ;
  21. $category = $_GET['Category'] ;
  22.  
  23. If ($Name == ""){
  24. If ($category == "No Category"){
  25. echo "You did not enter any details, please return to home page";
  26. }
  27. }
  28.  
  29.  
  30. If ($category =="No Category"){
  31. //Create PHP to store SQL query
  32. $query = "SELECT AnimalName, Category, BestPlaceToSee FROM animal WHERE AnimalName= '$Name'" ;}
  33. else {
  34. $query = "SELECT AnimalName, Category, BestPlaceToSee FROM animal WHERE Category= '$category'" ;
  35. }
  36. //Execute query
  37. $rows = mysql_query($query) or die(mysql_error());
  38.  
  39. //Check that the query has returned at least one result
  40. if (mysql_num_rows($rows)==0)
  41. {
  42. echo "Sadly, the query has no animal details to return for your search";
  43. //display error message
  44. }
  45. else
  46. {
  47. //display matching animal details in table
  48. //first row of table contains headings
  49.  
  50. echo '<table border="1" align="center"><tr><th>Animal Name</th><th>Category</th><th>Best Place To See</th>';
  51. while($Name = mysql_fetch_array($rows))
  52. //display each record returned by the query
  53. {
  54. echo '<tr><td>'.$Name['AnimalName'].'</td><td>'.$Name['Category'].'</td><td>'.$Name['BestPlaceToSee'].'</td></tr>';
  55. }
  56. echo"</table>";
  57. }
  58.  
  59.  
  60. //close server connection
  61. mysql_close($link);
  62.  
  63. //exit PHP
  64. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement