Reputation: 79
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
Reputation: 26784
Remove the quotes,quotes are for strings
NOW() + INTERVAL 10 MINUTE
Upvotes: 3
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
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