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!

Recommended Answers

All 4 Replies

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.'"';

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'";

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!

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.