Brenner Posted August 9, 2011 Share Posted August 9, 2011 Hi Guys - literally ripping my hair out on this one... I have the following function: function restoreSession() { mysql_connect("theHost", "root", "rootPWD") or die(mysql_error()); mysql_select_db("myDatabase") or die(mysql_error()); $restore_cmd = 'UPDATE wp_dor_cart66_sessions SET user_data = (SELECT user_data FROM wp_dor_cart66_stored_sessions WHERE ip_address = "' . $_SERVER['REMOTE_ADDR'] . '")'; $clean_up = "DELETE FROM `wp_dor_cart66_sessions` WHERE `ip_address` = \"" . $_SERVER['REMOTE_ADDR'] . "\" AND id NOT IN (SELECT id FROM ( SELECT id FROM `wp_dor_cart66_sessions` ORDER BY id DESC LIMIT 1 ) user_data )"; mysql_query($clean_up); mysql_query($restore_cmd); } THe clean up sql seems to work find - and if I echo out the $restore_cmd and paste it into phpMyAdmin - it works no problem... but I can absolutely not get it to work - it just refuses to update. *Edit* - here is the echo out of the $restore_cmd UPDATE wp_dor_cart66_sessions SET user_data = (SELECT user_data FROM wp_dor_cart66_stored_sessions WHERE ip_address = "196.54.110.24") Anyone having any ideas? I've literally lost a day on this thing - I'm completely out of ideas... Thanks in Advance! Quote Link to comment https://forums.phpfreaks.com/topic/244296-sql-code-works-in-phpmyadmin-but-not-mysql_query/ Share on other sites More sharing options...
Pikachu2000 Posted August 9, 2011 Share Posted August 9, 2011 You should return any mysql errors from the function, and var_dump or print_r whatever is returned. That will at least tell you if the query is failing in the function for some reason. Quote Link to comment https://forums.phpfreaks.com/topic/244296-sql-code-works-in-phpmyadmin-but-not-mysql_query/#findComment-1254716 Share on other sites More sharing options...
Brenner Posted August 9, 2011 Author Share Posted August 9, 2011 $result = mysql_query($restore_cmd) or die('Query failed: ' . mysql_error()); //changed //everything below was added echo "<br/>"; var_dump($result); echo "<br/>"; print_r($result); Doing this produces the following bool(true) 1 There doesn't seem to be an error... Quote Link to comment https://forums.phpfreaks.com/topic/244296-sql-code-works-in-phpmyadmin-but-not-mysql_query/#findComment-1254717 Share on other sites More sharing options...
fenway Posted August 9, 2011 Share Posted August 9, 2011 Echo the actual queries -- and make sure you actually have matching rows. Quote Link to comment https://forums.phpfreaks.com/topic/244296-sql-code-works-in-phpmyadmin-but-not-mysql_query/#findComment-1254995 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.