0

Can someone lend me a second pair of eyes? What is wrong with this code?

$sql = "INSERT INTO trips (firstname, lastname, email, tripfrom, tripdest, phonenum, seats, traveldate, traveltime, returndate, returntime, comments) VALUES ('$firstname', '$lastname', '$email', '$from', '$to', '$phonenum', '$seats', STR_TO_DATE('$traveldate', '%d/%m/%Y'), date('H:i', strtotime('$traveltime')), STR_TO_DATE('$returndate', '%d/%m/%Y'), date('H:i', strtotime('$returntime')),'$comments')";

Insert Error: ERROR: Could not able to execute INSERT INTO trips (firstname, lastname, email, tripfrom, tripdest, phonenum, seats, traveldate, traveltime, returndate, returntime, comments) VALUES ('joyce', 'solomon', 'jmo@southe.com', 'Corp', 'Hert', '207-977-8706', '3', STR_TO_DATE('31/10/2016', '%d/%m/%Y'), date('H:i', strtotime('6:00')), STR_TO_DATE('04/11/2016', '%d/%m/%Y'), date('H:i', strtotime('22:00')),'This is a test'). 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 ' strtotime('6:00')), STR_TO_DATE('04/11/2016', '%d/%m/%Y'), date('H:i', strtotim' at line 1

user396123
  • 59
  • 1
  • 2
  • 12

1 Answers1

0

You have "H:i" instead of 'H:i' and the double qoutes break the sql string

 "INSERT INTO trips (firstname, lastname, email, tripfrom, tripdest, phonenum, 
 seats, traveldate, traveltime, returndate, returntime, comments) VALUES 
 ('$firstname', '$lastname', '$email', '$from', '$to', '$phonenum',
  '$seats', STR_TO_DATE('$traveldate', '%d/%m/%Y'), 
  date('H:i', strtotime('$traveltime')), STR_TO_DATE('$returndate', '%d/%m/%Y'), 
  date('H:i', strtotime('$returntime')),'$comments')";

and you are trying to convert an Hour:minte . date date('H:i', strtotime('$traveltime'))

you should conver da datetime in date could be you need only

  date('$traveltime')

Or If you want convert time format use DATE_FORMAT($traveltime, "%H:%i")

ScaisEdge
  • 131,976
  • 10
  • 91
  • 107