7 Replies - 321 Views - Last Post: 01 April 2017 - 07:57 AM

#1 mglp  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 31-March 17

UPDATE SQL Syntax Error

Posted 01 April 2017 - 05:34 AM

I get the following error message. I've cehecked & rechecked my code many times and tried with different alternatives but I keep getting this error. All my names are correct - checked and rechecked many times.

Can someone see what the error is (and save my sanity)?

Error Message = 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 ''users' SET userid = test1, pswd = , authority = u, pddate = --, expdate = ' at line 1

$query = "UPDATE 'users' SET 'userid' = $UserID, 'pswd' = $Pswd, 'authority' = $Authority, 'pddate' = $dpdate, 'expdate' = $expdate, 'usermail' = $EMail, 
'amtpaid' = $pdamt, 'comp' = $comp WHERE 'userid' = $UserID";



Many thanks

Is This A Good Question/Topic? 0
  • +

Replies To: UPDATE SQL Syntax Error

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 13389
  • View blog
  • Posts: 53,429
  • Joined: 12-June 08

Re: UPDATE SQL Syntax Error

Posted 01 April 2017 - 05:49 AM

Print out your query with data before using it. Make sure it is being filled right.
Was This Post Helpful? 0
  • +
  • -

#3 mglp  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 31-March 17

Re: UPDATE SQL Syntax Error

Posted 01 April 2017 - 06:43 AM

Sorry but I don't understand what you mean.
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 13389
  • View blog
  • Posts: 53,429
  • Joined: 12-June 08

Re: UPDATE SQL Syntax Error

Posted 01 April 2017 - 06:47 AM

Print out the contents of '$query' before you use it to make sure your UPDATE statement looks legit. You should be using parameters, but hey - small steps first.
Was This Post Helpful? 0
  • +
  • -

#5 andrewsw  Icon User is online

  • lashings of ginger beer
  • member icon

Reputation: 6337
  • View blog
  • Posts: 25,550
  • Joined: 12-December 12

Re: UPDATE SQL Syntax Error

Posted 01 April 2017 - 06:51 AM

Table and field names are delimited by back ticks not single quotes.

Text values need to be delimited by single quotes, or preferably use parameters.

Still print out $query and test it separately.
Was This Post Helpful? 0
  • +
  • -

#6 mglp  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 31-March 17

Re: UPDATE SQL Syntax Error

Posted 01 April 2017 - 07:08 AM

Got you on the printing. Am checking it out.Will follow-up.

Re Back Ticks vs Single Quotes, I've always used Single Quotes and it always worked such as in

$query = "INSERT INTO users VALUES('$UserID','$Pswd','$Authority','$dpdate','$expdate','$EMail','pdamt','$comp')";


Was This Post Helpful? 0
  • +
  • -

#7 andrewsw  Icon User is online

  • lashings of ginger beer
  • member icon

Reputation: 6337
  • View blog
  • Posts: 25,550
  • Joined: 12-December 12

Re: UPDATE SQL Syntax Error

Posted 01 April 2017 - 07:27 AM

That is with values, not field names.
Was This Post Helpful? 1
  • +
  • -

#8 mglp  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 31-March 17

Re: UPDATE SQL Syntax Error

Posted 01 April 2017 - 07:57 AM

You solved the mystery. I used back Tick for field names and Single Quote for values and it works.

1000 Thanks!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1