1

i've been trying to insert a row into an Sql database table , and that row's last column is supposed to contain a variable and i can't figure out how to concatenate that variable with a date function. The problem becomes the single quote marks

$SQL = "INSERT INTO news VALUES (NULL, '$user', '$text'.'date('Y-m-d H:i:s')')";

That $text is supposed to have a "date now" function called right after it so that i would have the date that it was inserted into the table...

Thanks

2 Answers 2

2

Try this:

$sql = "INSERT INTO news VALUES (NULL, '$user', '$text<br>".date('Y-m-d H:i:s')."')";
Sign up to request clarification or add additional context in comments.

3 Comments

Someone edited my answer to erroneously change the code, why people do that? I've edited it back.
No, that person proposed an edit. Then people approve. This is a far more complex social issue [...]. Just rollback
@user2227494 It's working perfectly fine in this demo codepad.org/MKk6juoM You probably have an error somewhere else.
0

You can try this

$SQL = "INSERT INTO news VALUES (NULL, '$user', '".$text." now()')";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.