[thelist] MySQL/PHP Search

Jennifer Zelazny web at calgb.org
Wed Sep 3 15:03:51 CDT 2003


Hello.  I have a need to have my users search our MySQL database which 
contains people's names, phone numbers, etc so I found an example here: 
http://www.thinkhost.com/services/kb/php-mysql-forms.shtml and copied 
and pasted everything exactly like the article stated so I could see 
how this worked.  I only changed the hostname, username, and password.  
I set up a test database that was exactly like the one they used, so 
the only difference should by my hostname, username, password.  I have 
other PHP/MySQL applications running on my server which I supply the 
same hostname, username, and password information that work great, but 
I cannot figure out why this is failing.  If anyone has any ideas or 
thoughts...or working examples of a php/mysql search that I could look 
at, I would greatly appreciate it.

I get a parse error on the line: MYSQL_CONNECT($hostname, $username, 
$password) OR DIE("DB connection unavailable");

Thanks in advance,
Jen

-----------------
My code for the results page:

<html>
<head>
<title>Test</title>
</head>
<body bgcolor="#ffffff">
<center>
<table border="1" cellpadding="5" cellspacing="0" bordercolor="#000000">
<tr>
<td width="60"><b>id</b></td>
<td width="100"><b>name</b></td>
<td width="70"><b>telephone</b></td>
<td width="150"><b>birthday</b></td>
</tr>
<tr>
<td>
<? $hostname = "128.x.x.x"; // The DB server. 
$username = "root"; // The username you created for this database.  
$password = "xxxxx"; // The password you created for the username.  
$usertable = "details"; // The name of the table you made. 
$dbName = "example"; // This is the name of the database you made. 
MYSQL_CONNECT($hostname, $username, $password) OR DIE("DB connection 
unavailable");
@mysql_select_db( "$dbName") or die( "Unable to select database"); 
?> 
<? 
//error message (not found message)begins 
$XX = "No Record Found, to search again please close this window"; 
//query details table begins
$query = mysql_query("SELECT * FROM details WHERE $metode LIKE 
'%$search%' LIMIT 0, 50"); 
while ($row = @mysql_fetch_array($query)) 
{ 
$variable1=$row["id"];
$variable2=$row["name"]; 
$variable3=$row["telephone"]; 
$variable4=$row["birthday"];
//table layout for results 

print ("<tr>");
print ("<td>$variable1</td>"); 
print ("<td>$variable2</td>"); 
print ("<td>$variable3</td>"); 
print ("<td>$variable4</td>"); 
print ("</tr>"); 
}
//below this is the function for no record!!
if (!$variable1)
{ 
print ("$XX");
} 
//end 
?>
</table>
</center>

</body>

</html> 


More information about the thelist mailing list