1

I have this pre-existing table structure (yes data and time are terrible names but they are already there): enter image description here

However everything grinds to a halt on updating the in/out field. (Also tried with prepared statements: no luck)

This does not work:

$update_punch = $conn->query("UPDATE ttime SET date='$the_edited_date_w_mysql', time='$the_edited_time', inout='$the_ins_and_outs' WHERE id='$the_id' LIMIT 1");

The first line of this works but it chokes on the 2nd (chocks with inout being a var or 'in':

$update_punch = $conn->query("UPDATE ttime SET date='$the_edited_date_w_mysql', time='$the_edited_time' WHERE id='$the_id' LIMIT 1");   
$update_punch = $conn->query("UPDATE ttime SET inout='$the_ins_and_outs' WHERE id='$the_id' LIMIT 1");

Here is there error:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 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 'inout='out' WHERE id='171366' LIMIT 1' at line 1' in /site/updatepunchesbystore2.php:43 Stack trace: #0 /site/updatepunchesbystore2.php(43): PDO->query('UPDATE ttime SE...') #1 {main} thrown in /site/updatepunchesbystore2.php on line 43

I have fought with it for an hour and I'm stumped!

Any thoughts?

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
Chris Cummings
  • 1,538
  • 2
  • 24
  • 39

2 Answers2

1

wrap the keywords in backticks

`inout`='$the_edited_time'

should work for you

andrew
  • 9,313
  • 7
  • 30
  • 61
  • This did it...I worried so much about date and time that it never occured to me that inout could be a reserved word in MySQL. Backticks fixed it. Thanks! – Chris Cummings Jun 12 '14 at 22:18
0

Try this:

$qry= "UPDATE ttime SET `inout`='{$the_ins_and_outs}' WHERE id='$the_id'";
$update_punch = $conn->query($qry);
Hackerman
  • 12,139
  • 2
  • 34
  • 45