Jump to content

Insert NOW() from Array? Escape Issue?


Go to solution Solved by Barand,

Recommended Posts

Hi,

 

I'm currently passing an array of values to be updated in my database, but am struggling on the best way to escape the quotation marks around the NOW statement below, as understand this will only work without them.
 

This is what is being passed to the DB which does not currently work. I'm seeking some help to find the best way to remove the "" from around the NOW statement, but retain it in the array structure which i believe needs the '' to understand its a value.

UPDATE staff SET staff_last_login="NOW()" WHERE staff_id="1" 
array('staff_last_login'=>'NOW()')

My question is - whats the best way to escape this?

 

I understand forward slashes can sometimes be used, and double quotes - but feel like i have exhausted all my known options.

 

Any help much appreciated.

 

MoFish

Link to comment
https://forums.phpfreaks.com/topic/291435-insert-now-from-array-escape-issue/
Share on other sites

MoFish,

 

You problem doesn't make sense. When you define an array value such as this

 

array('staff_last_login'=>'NOW()')

 

The quotes are used as delimiters to define where the value starts and ends. They are not part of the value. So, if you use that array value in generating your query, there will be no quotes.

 

 

$data = array('staff_last_login'=>'NOW()');
$query = "UPDATE staff SET staff_last_login={$data['staff_last_login']} WHERE staff_id='1'";
echo $query; //Output: UPDATE staff SET staff_last_login=NOW() WHERE staff_id='1'
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.