Advertisement
Guest User

Heggie......

a guest
Feb 8th, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 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 ($category =="No Category"){
  24. //Create PHP to store SQL query
  25. $query = "SELECT AnimalName, Category, BestPlaceToSee FROM animal WHERE AnimalName= '$Name'" ;}
  26. else {
  27. $query = "SELECT AnimalName, Category, BestPlaceToSee FROM animal WHERE Category= '$category'" ;
  28. }
  29. //Execute query
  30. $rows = mysql_query($query) or die(mysql_error());
  31.  
  32. //Check that the query has returned at least one result
  33. if (mysql_num_rows($rows)==0)
  34. {
  35. echo "Sadly, the query has no animal details to return for your search";
  36. //display error message
  37. }
  38. else
  39. {
  40. //display matching animal details in table
  41. //first row of table contains headings
  42.  
  43. echo '<table border="1" align="center"><tr><th>Animal Name</th><th>Category</th><th>Best Place To See</th>';
  44. while($Name = mysql_fetch_array($rows))
  45. //display each record returned by the query
  46. {
  47. echo '<tr><td>'.$Name['AnimalName'].'</td><td>'.$Name['Category'].'</td><td>'.$Name['BestPlaceToSee'].'</td></tr>';
  48. }
  49. echo"</table>";
  50. }
  51.  
  52.  
  53. //close server connection
  54. mysql_close($link);
  55.  
  56. //exit PHP
  57. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement