I have a query that was working fine, but I recently switched hosts. I couldn't tell you what version of MySQL was on the old host, but I am now on version 5.0.67. The query asks for multiple fields using AND and LIKE. My error message is telling me there may be something wrong with my syntax. Anyone care to help me out? Here's what I got...
<?
// Get the search variable from URL
$num = @$_GET['num'] ;
$loop = @$_GET['loop'] ;
$type = @$_GET['type'] ;
$elec = @$_GET['elec'] ;
$handi = @$_GET['handi'] ;
$trimmednum = trim($num); //trim whitespace from the stored variable
$var = $num . $loop . $type . $elec . $handi ;
// trying to get rid of %
if ($loop=="%")
{ $l="Any Loop"; }
if ($type=="%")
{ $t="Any Type"; }
if ($elec=="%")
{ $e="Both Electric and Non-electric"; }
if ($handi=="%")
{ $h="Both Accessible and Not Accessible"; }
if (!isset($l))
{$l=$loop;}
if (!isset($t))
{$t=$type;}
if (!isset($e))
{$e=$elec;}
if (!isset($h))
{$h=$handi;}
// rows to return
$limit=20;
// check for an empty string and display a message.
if ($var == "")
{
echo "<p>Please enter a search...</p>";
echo "</td></tr></table>";
include('../footer.php');
echo "</body></html>";
exit;
}
// check for a search parameter
if (!isset($var))
{
echo "<p>We dont seem to have a search parameter!</p>";
exit;
}
mysql_connect(...); //(host, username, password)
mysql_select_db(...) or die("Unable to select database"); //select which database we're using
// Build SQL Query
$query = "SELECT * FROM table1 WHERE (Number LIKE '%$num')
AND (Loop LIKE '$loop') AND (Site_Type LIKE '$type')
AND (Electricity LIKE '$elec') AND (Handicap like '$handi')
ORDER BY Loop, Number";
$numresults=mysql_query($query) or die(mysql_error());
$numrows=mysql_num_rows($numresults);
Thanks