Jump to content

SQL Code works in PhpMyAdmin but not mysql_query


Brenner

Recommended Posts

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!

Link to comment
Share on other sites

              $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...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.