greencoin Posted June 28, 2007 Share Posted June 28, 2007 Looks like I closed the other post too soon. Here's my code: Page1 <? <form method="POST" action="track_area_results.php"> Select the states to search <table width="500" border="0" cellspacing="0" cellpadding="0"> <tr> <td><input type="checkbox" name="state[]" value="ak"> AK</td> etc etc... ?> Page2: <?php $name2 = $_POST['name2']; for($name2array=0; $name2array < sizeof($name2); $name2array++) { if($name2array < (sizeof($name2)-1)) { $name2_cond = " OR "; } else { $name2_cond = ""; } $name2q = $name2q."`name2` LIKE'".$name2[$name2array]."'$name2_cond"; // I'm thinking this is the problem code } $name2q = "($name2q)"; $query = "SELECT * FROM GC_Tracker WHERE $name2q"; // I'm assuming this is the line one referenced in the error // as the only code on line one is the mysql_connect // function which I know is working. $result = mysql_query($query) or die(mysql_error()); if ($result = mysql_query($sql)) { etc etc... ?> Which kicked out an error: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1" I'm a n00b and don't know the first thing about coding variations in MySQL versions and syntax erros drive me nuts! My MySQL is version 4.1 hosted by Godaddy. Anyone see anything the matter? Thanks again ~Rich Quote Link to comment Share on other sites More sharing options...
trq Posted June 28, 2007 Share Posted June 28, 2007 Your missing the comparison in your WHERE clause. Example... SELECT foo FROM bar WHERE fld = value; You simply have.... SELECT foo FROM bar WHERE fld; Quote Link to comment Share on other sites More sharing options...
greencoin Posted June 28, 2007 Author Share Posted June 28, 2007 OK OK - I checked a little closer and found that my checkbox string did not match what my $_POST[] was looking for so I changed it and now it tells me : Query failed Query was empty I'm going to double check my table but I'm quite certain that field is full. Any tips on troubleshooting the problem? ~Rich btw, I posted this before I read what thorpe had posted Quote Link to comment Share on other sites More sharing options...
trq Posted June 28, 2007 Share Posted June 28, 2007 Any tips on troubleshooting the problem? Place... die($query); prior to executing mysql_query(), this will let you see what the actual query looks like. Quote Link to comment Share on other sites More sharing options...
greencoin Posted June 28, 2007 Author Share Posted June 28, 2007 Very nice. Here's what I got with a single checkbox checked; SELECT * FROM GC_Tracker WHERE (`area` LIKE'ak') And with 2 checked; SELECT * FROM GC_Tracker WHERE (`area` LIKE'ak' OR `area` LIKE'la') Does this look right for MySQL 4.1? Aren't the single quotes supposed to be double quotes? ~Rich Quote Link to comment Share on other sites More sharing options...
greencoin Posted June 28, 2007 Author Share Posted June 28, 2007 OK - so I modified the code to; <?php $name2q = $name2q."\"area\" LIKE'".$name2[$name2array]."'$name2_cond"; // put area in doubles quotes } $name2q = "($name2q)"; $query = "SELECT * FROM GC_Tracker WHERE $name2q";?> which gives me the correct query output of; "SELECT * FROM GC_Tracker WHERE ("area" LIKE'ak') but it's still telling me the query failed, query was empty. I know the table has the info.. I tried a query with all 50 boxes checked, tried a query with one box checked (with a known matching record). I am now "officially" totally lost. ??? Anyone? ~Rich Quote Link to comment Share on other sites More sharing options...
greencoin Posted June 28, 2007 Author Share Posted June 28, 2007 OK again, figured out what I was doing wrong to cause the "Query was empty" <?php $result = mysql_query($query) or die(mysql_error()); \\ changed $result to $sql if ($result = mysql_query($sql)) \\ there is no $sql variable defined!! ?> Ahh, the joy of recycling code. Now I have a different error with a much more ominous error message that I'm going to post in a new thread. Thanks for the help Thorpe. Case closed! ~Rich Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.