How to write this INSERT to make it work

Basically, I want to put "today" year, month, day on two fields ... something like the following. Tried variables but can't get it right.

"INSERT INTO film_out (start_year, start_month, start_day), (end_year, end_month, end_day) VALUES ('$ year', '$ month', '$ day')"

+1


source to share


3 answers


?



"INSERT INTO film_out (start_year, start_month, start_day, end_year, end_month, end_day)
      VALUES ('$year', '$month', '$day', '$year', '$month', '$day')"

      

+2


source


INSERT INTO film_out 
(start_year, start_month, start_day, end_year, end_month, end_day) 
VALUES 
(?,?,?,?,?,?)

      

You have six columns, so you need six values.



If you have two sets of three values, you need to repeat the same values.

You want to use bind variables instead of direct interpolation (instead of "$ year").

+2


source


Don't know what the column types are, so I assume they are numeric ...

INSERT INTO film_out (start_year, start_month, start_day, end_year, end_month, end_day)
VALUES (YEAR(), MONTH(NOW()), DAYOFMONTH() + 1, YEAR(), MONTH(NOW()), DAYOFMONTH() + 1)

      

+1


source







All Articles