3

I keep getting the error:-

"You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'Password='evertonblues' Forename='Josh' Surname='Edmondson' Date of Birth='199' at line 1"

error when running my update query.

$result = mysqli_query($con, "UPDATE Users SET Username='".$newUsername."' Password='".$newPassword."' Forename='".$newForename."' Surname='".$newSurname."' `Date of Birth`='".$newDateofBirth."'     Address='".$newAddress."' `Post Code`='".$newPostcode."' Email='".$newEmail."' `Phone Number`='".$newPhonenumber."' WHERE `User ID`='".$newUserid."';");
Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
DrivingFail
  • 43
  • 1
  • 5

2 Answers2

3

You forgot a bunch of commas:

..snip... SET Username='".$newUsername."' Password='".$newPassw
                                         ^-- and many others
Marc B
  • 356,200
  • 43
  • 426
  • 500
  • The commas did the trick boss, nice observation, im new to PHP and have spent hours on end looking at this code :P – DrivingFail Mar 10 '16 at 14:47
  • Nothing to do with php, really. that's purely an sql-level problem. php just happens to be a wrapper around that sql – Marc B Mar 10 '16 at 16:33
1

Use query as below:

"UPDATE Users SET `Username`='".$newUsername."', `Password`='".$newPassword."', `Forename`='".$newForename."', `Surname`='".$newSurname."', `Date of Birth`='".$newDateofBirth."', `Address`='".$newAddress."', `Post Code`='".$newPostcode."', `Email`='".$newEmail."', `Phone Number`='".$newPhonenumber."' WHERE `User ID`='".$newUserid."';");

Also space in Date of Birth

Apoorv
  • 231
  • 1
  • 8
  • Spaces don't matter. It's properly escaped with back tics. If they did matter `Post Code` would also be a problem. – xQbert Mar 10 '16 at 14:44
  • This one worked, thank you so much, just spent the last 3 hours getting annoyed over my code, im new to PHP too so that doesn't help :P – DrivingFail Mar 10 '16 at 14:46