0

I have an HTML form with three dropdown selects:
month, day and year.
I have four fields in my MySQL table:
month, day, year, and date.
The 'date' field is supposed to contain the concatenated values of the year, month and day separated by dashes.
I write this in my PHP:

$data = "UPDATE inventors SET month='$month',
day='$day', year='$year', date='$year . "-" . $month . "-" . $day' 
WHERE lastname=".'"'.$lastname.'"';

The concatenation doesn't work.
What am I doing wrong?

Thank you!

3
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by levsha
0

make the change in your query as hightligted below

$data = "UPDATE inventors SET month='$month',
day='$day', year='$year', [b]date='{$year}-{$month}-{$day}'[/b] 
WHERE lastname=".'"'.$lastname.'"';
0

I have an HTML form with three dropdown selects:
month, day and year.
I have four fields in my MySQL table:
month, day, year, and date.
The 'date' field is supposed to contain the concatenated values of the year, month and day separated by dashes.
I write this in my PHP:

$data = "UPDATE inventors SET month='$month',
day='$day', year='$year', date='$year . "-" . $month . "-" . $day' 
WHERE lastname=".'"'.$lastname.'"';

The concatenation doesn't work.
What am I doing wrong?

Thank you!

the concatenation full stops seem to be inside the string. try this:

$data = "UPDATE inventors SET month='$month',day='$day', year='$year', date='$year" . "-" . "$month" . "-" . "$day' WHERE lastname='$lastname'";
0

make the change in your query as hightligted below

$data = "UPDATE inventors SET month='$month',
day='$day', year='$year', [b]date='{$year}-{$month}-{$day}'[/b] 
WHERE lastname=".'"'.$lastname.'"';

Leviathan's solution worked, but I'm going to try out yours as well, just to have an extra way to do this. :)
Thank you so much!

0

the concatenation full stops seem to be inside the string. try this:

$data = "UPDATE inventors SET month='$month',day='$day', year='$year', date='$year" . "-" . "$month" . "-" . "$day' WHERE lastname='$lastname'";

Thank you so, so much!
It worked.
I'm marking the thread solved.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.