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

 

??? ??? ???

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.