Dragen Posted May 16, 2007 Share Posted May 16, 2007 Okay, I'm quite tired so I may just be being really dim witted here, but.. what's wrong with this mysql statement? $sqlsel = "SELECT * FROM times WHERE day = '".$day."' && group = '".$group."' && start = '".$start."'"; I've been staring at it for some time and just can't see the problem. Maybe I just need some sleep... Whenever I try and run it it gives me this error message: 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 'group = 'Pre-School' && start = '9:30'' at line 1 I just can't see what's wrong... Quote Link to comment https://forums.phpfreaks.com/topic/51742-solved-simple-mysql-statement-giving-error-cant-figure-it-out/ Share on other sites More sharing options...
kathas Posted May 16, 2007 Share Posted May 16, 2007 the and operator is not && it is 'and' without the quotes of course... Quote Link to comment https://forums.phpfreaks.com/topic/51742-solved-simple-mysql-statement-giving-error-cant-figure-it-out/#findComment-254866 Share on other sites More sharing options...
Dragen Posted May 16, 2007 Author Share Posted May 16, 2007 Thanks, but that's not it. You can use both '&&' or 'and'. I did try it with and though and it didn't work. I'm just stumped.. I can't see anything wrong with the syntax Quote Link to comment https://forums.phpfreaks.com/topic/51742-solved-simple-mysql-statement-giving-error-cant-figure-it-out/#findComment-254868 Share on other sites More sharing options...
boo_lolly Posted May 16, 2007 Share Posted May 16, 2007 the and operator is not && it is 'and' without the quotes of course... actually, i believe it can be done either way. anyway, try this: $sqlsel = " SELECT * FROM times WHERE day = '".$day."', group = '".$group."', start = '".$start."' "; Quote Link to comment https://forums.phpfreaks.com/topic/51742-solved-simple-mysql-statement-giving-error-cant-figure-it-out/#findComment-254869 Share on other sites More sharing options...
john010117 Posted May 16, 2007 Share Posted May 16, 2007 Try this: $sqlsel = "SELECT * FROM times WHERE day = '$day' AND group = '$group' AND start = '$start'"; I'm just throwing ideas around... Quote Link to comment https://forums.phpfreaks.com/topic/51742-solved-simple-mysql-statement-giving-error-cant-figure-it-out/#findComment-254870 Share on other sites More sharing options...
Dragen Posted May 16, 2007 Author Share Posted May 16, 2007 nope, no good.... Quote Link to comment https://forums.phpfreaks.com/topic/51742-solved-simple-mysql-statement-giving-error-cant-figure-it-out/#findComment-254871 Share on other sites More sharing options...
kathas Posted May 16, 2007 Share Posted May 16, 2007 try echoing your query to see if there is something wrong with it... like a single quote in $day or $group or $start Quote Link to comment https://forums.phpfreaks.com/topic/51742-solved-simple-mysql-statement-giving-error-cant-figure-it-out/#findComment-254872 Share on other sites More sharing options...
john010117 Posted May 16, 2007 Share Posted May 16, 2007 Backticks sometimes solved my problems. $sqlsel = "SELECT * FROM `times` WHERE day = '$day' AND group = '$group' AND start = '$start'"; Make sure you've defined every variable that's in the query. Quote Link to comment https://forums.phpfreaks.com/topic/51742-solved-simple-mysql-statement-giving-error-cant-figure-it-out/#findComment-254873 Share on other sites More sharing options...
boo_lolly Posted May 16, 2007 Share Posted May 16, 2007 hmm, i just noticed something. you have 'Pre-School' in your where argument. mysql may not like the '-' in there. try doing this: $sqlsel = " SELECT * FROM times WHERE day = '". $day ."' AND group = '". str_replace('-', '\-', $group) ."' AND start = '". $start ."' "; Quote Link to comment https://forums.phpfreaks.com/topic/51742-solved-simple-mysql-statement-giving-error-cant-figure-it-out/#findComment-254874 Share on other sites More sharing options...
Dragen Posted May 16, 2007 Author Share Posted May 16, 2007 I've already thought of that.. I changed it to something else to test it.. I've also done the same with '9:30' as well, just in case it wasn't likng the ':' Quote Link to comment https://forums.phpfreaks.com/topic/51742-solved-simple-mysql-statement-giving-error-cant-figure-it-out/#findComment-254881 Share on other sites More sharing options...
boo_lolly Posted May 16, 2007 Share Posted May 16, 2007 I've already thought of that.. I changed it to something else to test it.. I've also done the same with '9:30' as well, just in case it wasn't likng the ':' well... what happened?? same error? Quote Link to comment https://forums.phpfreaks.com/topic/51742-solved-simple-mysql-statement-giving-error-cant-figure-it-out/#findComment-254887 Share on other sites More sharing options...
Dragen Posted May 16, 2007 Author Share Posted May 16, 2007 yeah, same thing.. I've just narrowed it down to the: && group = '".$group."' If I remove the group it works fine, but obviously it doesn't find what I want from the database (I just don't get errors..) Quote Link to comment https://forums.phpfreaks.com/topic/51742-solved-simple-mysql-statement-giving-error-cant-figure-it-out/#findComment-254891 Share on other sites More sharing options...
Dragen Posted May 16, 2007 Author Share Posted May 16, 2007 Okay I've sorted the problem... for some reason it didn't like my mysql cell being called group. I changed the name to sesgroup and it's working fine! perhaps group is a reserved name for something? I'd be interested to know. Thanks for all the help! Quote Link to comment https://forums.phpfreaks.com/topic/51742-solved-simple-mysql-statement-giving-error-cant-figure-it-out/#findComment-254909 Share on other sites More sharing options...
boo_lolly Posted May 16, 2007 Share Posted May 16, 2007 Okay I've sorted the problem... for some reason it didn't like my mysql cell being called group. I changed the name to sesgroup and it's working fine! perhaps group is a reserved name for something? I'd be interested to know. Thanks for all the help! of course! i can't believe i didn't see it before! GROUP is a mysql argument. http://www.tizag.com/mysqlTutorial/mysqlgroupby.php sorry i didn't recognise that sooner. glad you figured it out bro! don't forget to mark this topic as 'solved' Quote Link to comment https://forums.phpfreaks.com/topic/51742-solved-simple-mysql-statement-giving-error-cant-figure-it-out/#findComment-254914 Share on other sites More sharing options...
kenrbnsn Posted May 16, 2007 Share Posted May 16, 2007 The word "group" is a reserved word in MySQL. If you want to use a reserved word in another context in MySQL you need to surround the word with backticks -- "`" -- as in `group`. Ken Quote Link to comment https://forums.phpfreaks.com/topic/51742-solved-simple-mysql-statement-giving-error-cant-figure-it-out/#findComment-254915 Share on other sites More sharing options...
Dragen Posted May 16, 2007 Author Share Posted May 16, 2007 thanks! Quote Link to comment https://forums.phpfreaks.com/topic/51742-solved-simple-mysql-statement-giving-error-cant-figure-it-out/#findComment-254917 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.