dprichard Posted October 1, 2007 Share Posted October 1, 2007 ??? ??? ??? ??? Okay, I am so stuck. I have two variables. The first one interval has a value of 3 and the second one period has a value of day. I try to insert these into a database using date_add and curdate(), but am getting an error. Here is my Insert (the DATE_ADD is at the very end) mysql_query("INSERT INTO emp_time_table(empto_emp_id, empto_to_type_id, empto_accrual_start_date, empto_accrual_expiration_date, empto_plan_cap, empto_max_carry_over, empto_prev_carry_over, empto_renewal_term, empto_time_accrued, empto_time_used, empto_time_through, empto_last_updated, empto_updated_by, empto_waiting_period) VALUES ('$empto_emp_id', '$empto_type_id', '$empto_accrual_start_date', '$empto_accrual_expiration_date', '$empto_plan_cap', '$empto_max_carry_over', '$empto_prev_carry_over', '$empto_renewal_term', '$empto_time_accrued', '$empto_time_used', '$empto_time_through', '$empto_last_updated', '$empto_updated_by', DATE_ADD(CURDATE() ,INTERVAL '$interval' '$period')") or die(mysql_error()); Here is my 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 ')' at line 1 Any help you can give would be greatly appreciated. Thank you!!! ??? ??? ??? Quote Link to comment https://forums.phpfreaks.com/topic/71398-solved-getting-error-on-date_add-using-variables/ Share on other sites More sharing options...
fenway Posted October 1, 2007 Share Posted October 1, 2007 Echo the query after variable interpolation. Quote Link to comment https://forums.phpfreaks.com/topic/71398-solved-getting-error-on-date_add-using-variables/#findComment-359411 Share on other sites More sharing options...
dprichard Posted October 1, 2007 Author Share Posted October 1, 2007 Thank you... I did just that and saw that it was coming out wrong. I changed it to this DATE_ADD('$empto_accrual_start_date',INTERVAL $interval $period) and it worked. This single quote, double quote, no quote thing confuses me. Do you know of any good tutorials that explain it in like 2 year old terms? Thanks again for the help. Quote Link to comment https://forums.phpfreaks.com/topic/71398-solved-getting-error-on-date_add-using-variables/#findComment-359423 Share on other sites More sharing options...
fenway Posted October 1, 2007 Share Posted October 1, 2007 There are two issues here... php and mysql. MySQL only needs string literals quoted (typically with single quotes for ANSI compatablility), and special characters escaped. Everything else is "raw text". PHP needs strings quoted too, but will happily accept single/double quotes. However, in double quotes, php variables will be interpolated (substituted) before the string is evaluated. Quote Link to comment https://forums.phpfreaks.com/topic/71398-solved-getting-error-on-date_add-using-variables/#findComment-359425 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.