Jump to content

php search database problem


brad12345

Recommended Posts

hi all im trying to search my mysql database that has two tables one is the owner table and one is the pet table (its for a veterinarian website) im getting back some errors

 

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home/it224/bradk/public_html/assignment1/search.php on line 76

 

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home/it224/bradk/public_html/assignment1/search.php on line 99

 

My connection is fine because i can add new owners and pets etc and echo the database.

The lines where the two errors are coming from are labeled blatantly in the code

 

//Owner POST variables///
$phoneNumber = $_POST['phoneNumber'];
$address = $_POST['address'];
$ownerName = $_POST['ownerName'];


//Patient POST vaiables//
$petName = $_POST['petName'];
$petSpecies = $_POST['petSpecies'];
$petBreed = $_POST['petBreed'];
$petAge = $_POST['petAge'];
$petWeight = $_POST['petWeight'];

$search = $_POST['search'];


///If the Search form has been filled out execute this code///
if (isset($_POST['search']))
{
$selectString = "select * from tblPatientBK where petName = $petName AND petSpecies = $petSpecies AND petBreed = $petBreed AND petAge = $petAge AND petWeight = $petWeight";
$resultPatient = mysql_query($selectString);	

	echo ("<table border=1>");
echo ("<tr>");
echo ("<td width=100>petID</td>");
echo ("<td width=100>Name</td>");
echo ("<td width=100>Species</td>");
echo ("<td width=100>Breed</td>");
echo ("<td width=100>Age</td>");
echo ("<td width=100>Weight</td>");
echo ("<td width=100>ownerID</td>");
echo ("</tr>");	

////////////////////////////////////////////////////////////////////////////////
///////First error is  the line below////////////////////////////////////////
    while ($row = mysql_fetch_row($resultPatient))
		{

			echo("<tr>");		
			foreach($row as $value => $key)
				echo("<td width=100>$value</td>");  
				echo("</tr>");
		}
		echo("</table>");


	$selectString2 = "select * from tblOwnerBK where ownerName = $ownerName and address = $address and phoneNumber = $phoneNumber";
$resultPatient2 = mysql_query($selectString2);	

echo ("<table valign='top' border=1>");
echo ("<tr>");
echo ("<td valign='top' width=20><b>Owner ID</b></td>");
echo ("<td valign='top' width=20><b>Title</b></td>");
echo ("<td valign='top' width=200><b>Owner Name</b></td>");
echo ("<td valign='top' width=230><b>Address</b></td>");
echo ("<td valign='top' width=200><b>Phone Number</b></td>");
echo ("</tr>");	


////////////////////////////////////////////////////////////////////////////////
///////Second error is  the line below////////////////////////////////////////
    while ($row = mysql_fetch_row($resultPatient2))
		{

			echo("<tr>");		
			foreach($row as $value => $key)
				echo("<td width=100>$value</td>");  
				echo("</tr>");
		}
		echo("</table>");		
}
else  ///Beginning else code 
{

	//echo("$errorString");//

	echo("<h4>Search</h4>");
	echo("Please enter your search query");


	///Creating the form to handle the Search query that the user is filling out////
	echo ("<form action='$self' method='POST'>");
	echo ("<fieldset>");
	echo ("<legend>Pet Details</legend><p>");
		echo ("<table>");

		echo ("<tr>");
			echo ("<td width=200>Pet name : </td><td><input type='textbox' name='petName' value=''></td>");
		echo ("</tr>");

		echo ("<tr>");
			echo ("<td width=200>Species :  </td><td><input type='textbox' name='petSpecies' value=''></td>");
		echo ("</tr>");

		echo ("<tr>");
			echo ("<td width=200>Breed :    </td><td><input type='textbox' name='petBreed' value=''></td>");
		echo ("</tr>");

		echo ("<tr>");
			echo ("<td width=200>Age :      </td><td><input type='textbox' name='petAge' value=''></td>");
		echo ("</tr>");

		echo ("<tr>");
			echo ("<td width=200>Weight :   </td><td><input type='textbox' name='petWeight' value=''></td>");
		echo ("</tr>");

		echo ("</table>");
		echo ("</fieldset>");




		///Creating the second table within the form to handle the Owner search querys///
		echo ("<fieldset>");
	echo ("<legend>Owner Details</legend><p>");
		echo ("<table>");

				echo ("<table>");
	echo ("<tr>");
	echo ("<td width=200>Name                             : </td><td><input type='textbox' name='ownerName' value=''></td>");
	echo ("</tr>");
	echo ("<tr>");
	echo ("<td width=200>Address                          : </td><td><input type='textbox' name='address' value=''></td>");
	echo ("</tr>");
	echo ("<tr>");
	echo ("<td width=200>Phone Number                     : </td><td><input type='textbox' name='phoneNumber' value=''></td>");
	echo ("</tr>");
	echo ("</table>");

		echo ("</table>");
		echo ("</fieldset>");
		echo ("<br>");
		echo ("<input type='submit' name='search' value='Search'> <p>");

		echo ("</form>");



} // end of else

 

Thanks for any help you can provide

Link to comment
https://forums.phpfreaks.com/topic/100556-php-search-database-problem/
Share on other sites

Looks like sql syntax errors.

 

Use quotes around string variables

 

<?php
$selectString = "SELECT * from tblPatientBK 
               WHERE petName = '$petName' 
               AND petSpecies = '$petSpecies' 
               AND petBreed = '$petBreed' 
               AND petAge = $petAge 
               AND petWeight = $petWeight";


Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.