Jump to content

[SOLVED] Getting Error on Date_Add using Variables


dprichard

Recommended Posts

??? ??? ??? ???

 

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!!! 

 

??? ??? ???

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.