bravo14 Posted March 25, 2011 Share Posted March 25, 2011 Hi Guys I am trying to populate a field in a database with a the date 4 days from 'today'. I have used the query below, but I am getting an error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DATE_ADD(NOW(), INTERVAL 4 DAY))' at line 2 $add_vehicle_sql=mysql_query("INSERT INTO `tbl_auction_lot`(`cust_id`,`reserve`,`make`,`model`,`spec`,`fuel`,`doors`,`mot_date`,`fns`,`fos`,`rns`,`ros`,`condition`,`reg_no`,`service_history`,`sale_type`,`status`,`keepers`,`gearbox`,`emissions`,`colour`,`date_first_reg`,`date_manufacture`,`bhp`,`engine_size`,`end_date`) VALUES ('$seller_id','$reserve','$make','$model','$body_style','$fuel_type','$no_of_doors','$mot','$fns','$fos','$rns','$ros','$vehicle_condition','$vrm','$service_history','auction','$status','$prev_keepers','$gearbox','$emissions','$colour','$date_reg','$date_man','$bhp','$engine_size',DATE_ADD(NOW(), INTERVAL 4 DAY))") How would I do this? Quote Link to comment https://forums.phpfreaks.com/topic/231670-add-a-fixed-number-of-days-to-today/ Share on other sites More sharing options...
Twitch Posted March 25, 2011 Share Posted March 25, 2011 Maybe do something like this: <?php $four_days = mktime(0, 0, 0, date("m"), date("d")+4, date("y")); echo "4 days from now is ".date("m/d/y", $four_days); ?> Of course in your example you'd use the value to be entered into the database. Quote Link to comment https://forums.phpfreaks.com/topic/231670-add-a-fixed-number-of-days-to-today/#findComment-1192335 Share on other sites More sharing options...
PFMaBiSmAd Posted March 26, 2011 Share Posted March 26, 2011 Your query looks correct. I suspect there is something in one of the values that is breaking the sql syntax and the error is just detected at that point. I recommend that you form your sql query in a php variable and then echo that variable so that you can see what exactly the sql is. Quote Link to comment https://forums.phpfreaks.com/topic/231670-add-a-fixed-number-of-days-to-today/#findComment-1192350 Share on other sites More sharing options...
fenway Posted April 1, 2011 Share Posted April 1, 2011 I prefer the simpler "yourField + INTERVAL N DAY". Quote Link to comment https://forums.phpfreaks.com/topic/231670-add-a-fixed-number-of-days-to-today/#findComment-1195683 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.