I'm just tinkering with a simple timesheet script and if I do a simple insert into the db all is well. I can update the entry no problem either, my issue is that I want to update AND keep the information (which was working fine with the CONCAT I was using) but as soon as I use the ON DUPLICATE KEY UPDATE it breaks.
$sql="INSERT INTO sheet(employee, workdate, location, description, timein, timeout, timespent)
VALUES('$employee', CURDATE(), '$location', '$description', '$timein', '$timeout', '$timespent')";
//ON DUPLICATE KEY UPDATE
//location=VALUES(location),
//description=VALUES(description),
//timein=VALUES(timein),
//timeout=VALUES(timeout),
//timespent=VALUES(timespent)
//WHERE employee=$employee";
echo $sql;echo "<br>";
mysql_query($sql)or die(mysql_error());
If I uncomment the duplicate key I get a "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 'WHERE employee='Eric'' at line 9" error. Only thing I can think of is I'm doing this on a totally empty table but I figured the INSERT would have fixed that up. All my $variables are clean (no PDO, gotta learn that too) just real_escape_string
$sql="INSERT INTO sheet(employee, workdate, location, description, timein, timeout, timespent)
VALUES('$employee', CURDATE(), '$location', '$description', '$timein', '$timeout', '$timespent')
ON DUPLICATE KEY UPDATE
location=VALUES(location),
description=VALUES(description),
timein=VALUES(timein),
timeout=VALUES(timeout),
timespent=VALUES(timespent)
WHERE employee='$employee'";
echo $sql;echo "<br>";
mysql_query($sql)or die(mysql_error());