Jump to content

Insert NOW() from Array? Escape Issue?


MoFish

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'

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.