The script below runs on a private webserver at my office, within the displayresults() function I keep having the second query fail on me. I don't know why. Can anyone assist?
<?
//Database Variables
$hostname = "madeyoulook";
$username = "fortheusername";
$password = "andthepassword";
//Connecting to Database
MYSQL_CONNECT($hostname, $username, $password) or die ("DB connection unavailable");
MYSQL_SELECT_DB ('phone_dir') or die ("Unable to select to database");
//DECLARING GLOBALS
GLOBAL $grab,$sort;
//declaring other variable
$i=0;
//declaring a function to query the database
function displayresults($metode,$search,$ordered)
{
Global $i,$metode,$search;
//Display the top of results table
ECHO '<br> <table>
<tr>
<td width="100" bgcolor="#999999"><div align="center"><b><u><a href="'.htmlspecialchars("http://165.237.188.66/swd_it/phone_dir.php?sort=1&metode=".urlencode($metode)."&search=".urlencode($search)).'">Lastname</u></b></div></td>
<td width="100" bgcolor="#999999"><div align="center"><b><u><a href="'.htmlspecialchars("http://165.237.188.66/swd_it/phone_dir.php?sort=2&metode=".urlencode($metode)."&search=".urlencode($search)).'">Firstname</u></b></div></td>
<td width="81" bgcolor="#CCCCCC"><div align="center"><b><u><a href="'.htmlspecialchars("http://165.237.188.66/swd_it/phone_dir.php?sort=3&metode=".urlencode($metode)."&search=".urlencode($search)).'">Extension</u></b></div></td>
<td width="141" bgcolor="#999999"><div align="center"><strong><u><a href="'.htmlspecialchars("http://165.237.188.66/swd_it/phone_dir.php?sort=4&metode=".urlencode($metode)."&search=".urlencode($search)).'">Site</u></strong></div></td>
<td width="143" bgcolor="#999999"><div align="center"><strong><u><a href="'.htmlspecialchars("http://165.237.188.66/swd_it/phone_dir.php?sort=5&metode=".urlencode($metode)."&search=".urlencode($search)).'">Admin #</u></strong></div></td>
</tr>
</table>';
//SQL QUERY WHERE $metode = $_POST['metode'] and $search = $_POST['search'] and $ordered = the displayresults function argument.
$result = mysql_query("SELECT * FROM all_swr WHERE $metode LIKE '%$search%' ORDER BY $ordered ASC") or die ('RESULT QUERY FAILED');
//While Loop to list all matching resuts
while ($row = mysql_fetch_array($result))
{
//ALTERNATE ROW COLOR
IF ($i % 2 == 0)
{
$bgcolor = "#CCFFCC";
}
ELSE
{
$bgcolor = "#DDDDDD";
}
$site=$row['Site'];
//second query
$result1 = mysql_query("SELECT * FROM ADM_LDN WHERE '%$site%' LIKE Site") or die ('RESULT1 QUERY FAILED');
$row1=mysql_fetch_array($result1);
//table listing results
echo '
<table>
<tr bgcolor='.$bgcolor.'>
<td width="100"><center>'.$row["Lastname"].'</td>
<td width="100"><center>'.$row["Firstname"].'</td>
<td width="81"><B><center>'.$row["Extension"].'</b></td>
<td width="141"><center>'.$row["Site"].'</td>
<td width="143"><center>'.$row1["ADM_LDN"].'</td>
</tr>
</table>';
$i++;
}
//A little footer note on the last update of database information
echo '<br><B>End of Listing.</b><br><br><hr></center><font size="2"><i>Database last updated: 10/7/2004</i><hr>';
}
//Display the form
ECHO '
<table width="95%" border="0" cellspacing="0" cellpadding="4" bgcolor="#CCCCCC">
<tr>
<td height="16" bgcolor="#0099CC"><font size="5"><b>Southwest Division Phone Directory Search</b></font></td>
</tr>
</table>
<br>
<center>
<table width="300" height="90" border="4" cellpadding="0" cellspacing="0">
<tr>
<td width="290" bordercolor="#000000"><p align="center">
<form method="post" action="http://127.1.1.1/phone_dir.php?grab=1">
<select name="metode" size="1">
<option value="FirstName">First Name</option>
<option value="LastName" selected>Last Name</option>
<option value="Extension">Extension</option>
</select>
<input type="text" name="search" size="25">
Search database: <input type="submit" value="Go!!" name="Go"></form>
</td>
</tr>
</table>';
//Processing the main form and sorts
IF ($grab==1)
{
displayresults($metode,$search,"Site");
}
ELSEIF ($sort==1)
{
displayresults($metode,$search,"Lastname");
}
ELSEIF ($sort==2)
{
displayresults($metode,$search,"Firstname");
}
ELSEIF ($sort==3)
{
displayresults($metode,$search,"Extension");
}
ELSEIF ($sort==4)
{
displayresults($metode,$search,"Site");
}
ELSEIF ($sort==5)
{
displayresults($metode,$search,"ADM_LDN");
}
ELSE
{
//display some cosmetic stuff
echo'<p align="right"><img src="phone-handset.jpg" width="199" height="225" align="right"></p>
<P align="left"><A name=and><B><FONT face="Arial, sans-serif" color=#003399>A SPECIAL THANKS!</FONT></B></A>
<P align="left" class=indent><span class="style3"><FONT size=-1><b>A BIG THANKS to Steve Haviland for his CODE RE-WRITE for optimization and sorting! </b><br><i>Glad Tony was able to get that network card replaced, too!</i><br><br>The SWR search engine </FONT><FONT size=-1> ignores common words and characters such as "where" and "how" as they tend not to be real people-like names. If you do not provide sufficient search criteria, your search may yield too much information so please, keep it simple and spell it right. </FONT></span></P>
<P align="left"><A name=and><B><FONT face="Arial, sans-serif" color=#003399>Other </FONT></B><FONT face="Arial, sans-serif" color=#003399>Advanced <B>Search Features</B></FONT></A> </P>
<div align="left">
<LI><FONT size=-1><B>First Name :</B> Specify the FIRST name of the person for which you are searching. </FONT>
<LI><FONT size=-1><B>Last Name: </B> Specify the LAST name of the person for which you are searching. </FONT>
<LI><FONT size=-1><B>Extension: </B>You can reverse search on extension to return the associate user of the extension.</FONT>';
}
?>