php - Postegre sql update statement quotes issue

870

Im attempting to update a last access time in my database the problem im having is that im using postgres sql and for the strings I must use double quotes inside of single quotes, however this is throwing off the statement, is there a way to get around this

$sql= "UPDATE users SET last_access=' .date("Y-M-D", time ()).' WHERE login_id= '" .$login. "'";
pg_query($conn, $sql);
179

Answer

Solution:

$sql= "UPDATE users SET last_access='"
    .date("Y-m-d", time ()).
    "' WHERE login_id= '$login'";

or easier and cleaner using Postgresql's date:

$sql= "UPDATE users SET last_access = current_date WHERE login_id= '$login'";

People are also looking for solutions to the problem: php - if statement mistake on jquery

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.