user2897922
user2897922

Reputation: 79

SQL Type NOW() not working

I have this query;

"INSERT INTO download(download_key, ip, file, expire) VALUES ('".$text."', 
'".$mysql->real_escape_string($_SERVER['REMOTE_ADDR'])."', 
'".$searchQuery['file_match']."', 
'NOW() + INTERVAL 10 MINUTES')"

When I insert this in the database, the row expire is always 0000-00-00 00:00:00. I have tried the types:

But is always 0000-00-00 00:00:00 or 00:00:00.

What is the right type for NOW()? I`m using MYSQL

Upvotes: 0

Views: 267

Answers (4)

Mihai
Mihai

Reputation: 26784

Remove the quotes,quotes are for strings

NOW() + INTERVAL 10 MINUTE

Upvotes: 3

user2897922
user2897922

Reputation: 79

Thanks to @Kelu Thatsall: Fix:

NOW() + INTERVAL 10 MINUTE

Upvotes: 1

Kelu Thatsall
Kelu Thatsall

Reputation: 2541

I'm gonna add a little thing to people already said.

Except the thing you shouldn't pass sql functions as string so don't put NOW() + INTERVAL 10 MINUTES in quotes, you can pass a string for date also. You can generate this date with php for example.

Try this fiddle to check how to put simple DATE in database: http://sqlfiddle.com/#!2/cddc1/1

Also with PHP you can generate the date with this code:

$minutes = 10;
$date = date('Y-m-d H:i:s', time() + $minutes*60);
$query = "INSERT INTO download(download_key, ip, file, expire) VALUES ('$text', 
'{$mysql->real_escape_string($_SERVER['REMOTE_ADDR'])}', 
'{$searchQuery['file_match']}', 
'$date')";

Upvotes: 1

Ed Ganiukov
Ed Ganiukov

Reputation: 91

"INSERT INTO download(download_key, ip, file, expire) VALUES ('".$text."', 
'".$mysql->real_escape_string($_SERVER['REMOTE_ADDR'])."', 
'".$searchQuery['file_match']."', 
NOW() + INTERVAL 10 MINUTES)"

Upvotes: 1

Related Questions