MoFish Posted October 4, 2014 Share Posted October 4, 2014 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 Quote Link to comment https://forums.phpfreaks.com/topic/291435-insert-now-from-array-escape-issue/ Share on other sites More sharing options...
Solution Barand Posted October 4, 2014 Solution Share Posted October 4, 2014 (edited) One way around the problem would be array('staff_last_login'=>date('Y-m-d H:i:s')); Edited October 4, 2014 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/291435-insert-now-from-array-escape-issue/#findComment-1492710 Share on other sites More sharing options...
Psycho Posted October 4, 2014 Share Posted October 4, 2014 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' Quote Link to comment https://forums.phpfreaks.com/topic/291435-insert-now-from-array-escape-issue/#findComment-1492730 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.