Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //assign PHP variables for connection code
- $servername="localhost";
- $username="root";
- $password="";
- $database="wildscottrust";
- //connect to the database server
- $link=mysql_connect($servername,$username,$password) ;
- if(! $link)
- {
- die('Connection Failed'.mysql_error());
- }
- //Select Wild Scot Trust database
- mysql_select_db($database,$link) ;
- //Using GET assign PHP details
- $Name = $_GET['AnimalName'] ;
- $category = $_GET['Category'] ;
- If ($category =="No Category"){
- //Create PHP to store SQL query
- $query = "SELECT AnimalName, Category, BestPlaceToSee FROM animal WHERE AnimalName= '$Name'" ;}
- else {
- $query = "SELECT AnimalName, Category, BestPlaceToSee FROM animal WHERE Category= '$category'" ;
- }
- //Execute query
- $rows = mysql_query($query) or die(mysql_error());
- //Check that the query has returned at least one result
- if (mysql_num_rows($rows)==0)
- {
- echo "Sadly, the query has no animal details to return for your search";
- //display error message
- }
- else
- {
- //display matching animal details in table
- //first row of table contains headings
- echo '<table border="1" align="center"><tr><th>Animal Name</th><th>Category</th><th>Best Place To See</th>';
- while($Name = mysql_fetch_array($rows))
- //display each record returned by the query
- {
- echo '<tr><td>'.$Name['AnimalName'].'</td><td>'.$Name['Category'].'</td><td>'.$Name['BestPlaceToSee'].'</td></tr>';
- }
- echo"</table>";
- }
- //close server connection
- mysql_close($link);
- //exit PHP
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement