Click to See Complete Forum and Search --> : ALL scripts malfunction when "WHERE" used in search criteria
mkb116
01-28-2008, 04:00 AM
Hey guys I have a quick problem. I have several scripts that I have been troubleshooting. The scripts work fine but bring up NO results when I use WHERE in the search criteria for the database. It doesn't cause an error it just brings up no results. If i take it out it works fine but doesn't narror the results like needed.. Any help?
callumd
01-28-2008, 06:02 AM
Can you show us the relevant parts of the scripts in question?
TechEvangelist
01-28-2008, 06:37 AM
We need to see the code used for one of the SQL statements. Also, which database are you using?
The problem is most likely a syntax error in your statement. If the column name does not exist or a comparison value is not being passed to the statement or a string value is not quoted, then the statement will not work.
mkb116
01-28-2008, 02:14 PM
Ok here is the entire php script from one of my pages. It does not make an error it just always shows the "No results found please revise your search criteria."
Here is the page on the site http://www.ps-reviews.com/statesearch.php?shopstate=California
And if you click the browse link (which functions perfect) on the navigvation bar on the website it shows you that there are listings with "shopstate" as california so I can't figure out why its not coming up with the results OR showing an error in the script.
<?
include("dbinfo.inc.php");
mysql_connect('localhost',$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$XX = "No Records Found, please revise your search criteria. ";
$query="SELECT * FROM table1 WHERE shopstate = '$shopstate'";
$result=mysql_query($query);
$num=mysql_num_rows($result);
mysql_close();
$i=0;
while ($i < $num) {
$shopname=mysql_result($result,$i,"shopname");
$shopaddress=mysql_result($result,$i,"shopaddress");
$shopcity=mysql_result($result,$i,"shopcity");
$shopstate=mysql_result($result,$i,"shopstate");
$shopzip=mysql_result($result,$i,"shopzip");
$shopphone=mysql_result($result,$i,"shopphone");
$shopspecialty=mysql_result($result,$i,"shopspecialty");
echo "<tr><td>There are ". $shopname .", ". $shopaddress .", ". $shopcity .", ". $shopstate .", ". $shopzip .", ". $shopphone .", ". $shopspecialty ."</td></tr>";
++$i;
}
if (!$shopstate)
{
echo "<tr><td>$XX</td></tr>";
}
?>
mkb116
01-29-2008, 02:54 AM
To the top anyone? I know someone knows the answer to this haha.
cs3mw
01-29-2008, 04:23 AM
where are you assigning the variable $shopstate?
mkb116
01-29-2008, 04:24 AM
I just figured out it out.. FINALLY I was missing this $shopstate = @$_GET['shopstate'] ;
cs3mw
01-29-2008, 04:26 AM
sometimes you just need a second pair of eyes I always do it!