captjohneast Posted February 23, 2007 Share Posted February 23, 2007 Hello, I have spent the past couple of days trawling the forums and web trying to find a solution to my problem. Can you help? I am creating a query string by concatenating the results from a form submission. When I try parse the string it fails to return a result, but when I use the same string in the query browser, or using a string literal, I get the correct result. I have a feeling it is the way the concatenation is constructed. CODE SNIPS: // fails $query = "WHERE "; //form stuff... $query = $query."accGal=1 AND "; //form stuff... $query = $query."minXP>01 AND "; $query = $query."corpActive=1"; // fails $query = 'SELECT count(*) FROM tblcorps '.$_SESSION['corpQuery']; // were session var is 'WHERE accGal=1 AND minXP>0 and corpActive=1' echo $query // Returns exactly what I expect and can be used in the query browser with a successful result $result = MYSQL_QUERY( $query); // passes $query = 'SELECT count(*) FROM tblcorps WHERE accGal=1 AND minXP>0 and corpActive=1' $result = MYSQL_QUERY( $query); END SNIPS I have tried varios things with the concatenation such as: using mysql_real_escape_string() using " " instead of ' ' using " string $_SESSION['corpQuery'] string " using a standard variable instead of a session variable The various permitations do not work either. Probably something really simple but I am too tired to see... Thanks in advance. John Quote Link to comment Share on other sites More sharing options...
boo_lolly Posted February 23, 2007 Share Posted February 23, 2007 $query = $query."minXP>01 AND "; take out the first ';' Quote Link to comment Share on other sites More sharing options...
Barand Posted February 23, 2007 Share Posted February 23, 2007 replace $result = MYSQL_QUERY( $query); with $result = MYSQL_QUERY( $query) or die (mysql_error()); and see what it objects to Quote Link to comment Share on other sites More sharing options...
paul2463 Posted February 23, 2007 Share Posted February 23, 2007 try this way <?php / fails $query = "WHERE "; //form stuff... $query = "$query accGal=1 AND "; //form stuff... $query = "$query minXP > 0 AND "; $query = "$query corpActive=1"; ?> Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 23, 2007 Share Posted February 23, 2007 Why are you using the HTML code for >? Quote Link to comment Share on other sites More sharing options...
captjohneast Posted February 23, 2007 Author Share Posted February 23, 2007 Thanks all for the prompt reply, and the winner is ... removing the first ; from the escape greater than sign had not effect (but still return the correct greater than symbol) Changing the concaternation to $query = "$query accGal=1 AND " - still created the correct string but did not return what I expect (still fails) Barand! For telling the noob to follow good practise and handle exceptions... The exception revieled that the > was being escaped for PHP to > and re-escape by MySQL back to > Solution: didn't need to escape the Greater Than symbol in the first place.... Thanks for your help everyone. Quote Link to comment Share on other sites More sharing options...
captjohneast Posted February 23, 2007 Author Share Posted February 23, 2007 Sorry Jesirose. The code is for a personal project for the ingame browser an online game. Cheers, John Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 23, 2007 Share Posted February 23, 2007 ...I was asking why you're using > instead of >, not what the code was "for". 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.