Call NOW () function in MySQL

I am using php to create queries for mysql. Here is one of them:

UPDATE `subscribers` SET `curDate` = NOW() WHERE `e_mail` = "$resEmail"

curDate is a DateTime type. The problem is that after this request curDate of this letter

0000-00-00 00:00:00

What's wrong?

+3
source share
2 answers

Your PHP probably now looks like this:

$sql = 'UPDATE `subscribers` SET `curDate` = NOW() WHERE `e_mail` = "$resEmail"';

Single quotes do not allow you to replace the value of a variable in a string. You will need to change it to this:

$sql = "UPDATE `subscribers` SET `curDate` = NOW() WHERE `e_mail` = '$resEmail'";

You should also be aware that you might have a SQL injection vulnerability. Try using mysql_real_escape_string to avoid the email address.

$sql = "UPDATE `subscribers` SET `curDate` = NOW() WHERE `e_mail` = '" .
       mysql_real_escape_string($resEmail) . "'";
+5
source

timedate, , Timestamp(Now()).

0

Source: https://habr.com/ru/post/1743054/


All Articles