ToonMariner Posted June 1, 2007 Share Posted June 1, 2007 Hi, Posting this in here as the query itself is ok but.... OK I have this query.... $qry = ' SELECT `t`.* , `s`.`service_name` FROM `tips` AS `t` , `services` AS `s` , `customers` AS `c` WHERE `t`.`service_id` = `s`.`service_id` AND `c`.`user_id` = ' . $_SESSION['user_id'] . ' AND `t`.`tip_date` < DATE_ADD(`c`.`startdate`, INTERVAL 90 DAY) AND `t`.`result` IS NULL ORDER BY `t`.`tip_date` DESC '; echo $qry; $qry = mysql_query($qry) or die(mysql_error()); If I run the query directly in phpmyadmin (with session['user_id'] as a value) it returns the results as expected. Running the self same query through php I get this 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 13 I am running this locally - php 4.4.4 mysql 4.1.21. Can anyone suggest why this error is reported when the query is fine in phpmyadmin??? Many thanks. Quote Link to comment https://forums.phpfreaks.com/topic/53863-strange-query-behaviour/ Share on other sites More sharing options...
TreeNode Posted June 1, 2007 Share Posted June 1, 2007 Your PHP variables have apostrophes in them? Quote Link to comment https://forums.phpfreaks.com/topic/53863-strange-query-behaviour/#findComment-266296 Share on other sites More sharing options...
ToonMariner Posted June 2, 2007 Author Share Posted June 2, 2007 You mean $_SESSION['user_id']? No that is the correct way to reference an string index... if you would use $_SESSION[user_id] then may I suggest you change - its all about code style, consitency and support. In future the php engine may refuse to recognize the non-quote method... Quote Link to comment https://forums.phpfreaks.com/topic/53863-strange-query-behaviour/#findComment-266630 Share on other sites More sharing options...
umbrella_thing Posted June 2, 2007 Share Posted June 2, 2007 Yeah there is an error with your SQL script (darr) Maybe delete each clause to try and figure out which part of the script is giving you the error or something? I think phpmyadmin re-formats the SQL you give it sometimes to make it work... Just a thought... Quote Link to comment https://forums.phpfreaks.com/topic/53863-strange-query-behaviour/#findComment-266636 Share on other sites More sharing options...
penguin0 Posted June 2, 2007 Share Posted June 2, 2007 I think I had this proble as well, get rid of all the ` and ` Quote Link to comment https://forums.phpfreaks.com/topic/53863-strange-query-behaviour/#findComment-266639 Share on other sites More sharing options...
AndyB Posted June 2, 2007 Share Posted June 2, 2007 So what happens when you copy the echo'd query string into phpMyAdmin. Looks as though the online version doesn't get a value for the session variable. Quote Link to comment https://forums.phpfreaks.com/topic/53863-strange-query-behaviour/#findComment-266658 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.