7 Replies - 507 Views - Last Post: 26 March 2013 - 07:20 PM Rate Topic: -----

#1 liaml7  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 3
  • Joined: 26-March 13

PHP and SQL not working. Keeps giving error

Posted 26 March 2013 - 12:05 PM

The code is
UPDATE chats SET text1='".$text1."' text2='".$text2."' text3='".$text3."' text4='".$text4."' text5='".$text5."' text6='".$text6."' text7='".$text7."' text8='".$text8."' text9='".$text9."' text10='".$text10."' text11='".$text11."' text12='".$text12."' text13='".$text13."' text14='".$text14."' text15='".$text15."' text16='".$text16."' text17='".$text17."' text18='".$text18."' text19='".$text19."' text20='".$text20."' WHERE name='".$data."' AND password='".$data2."';

It seems correct and I've ran it on SQL testers and it works but it doesn't work on my website. It keeps saying "You have an error in your SQL syntax;"... "near 'text='def' text3='def' '"...

Is This A Good Question/Topic? 0
  • +

Replies To: PHP and SQL not working. Keeps giving error

#2 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3103
  • View blog
  • Posts: 10,898
  • Joined: 08-August 08

Re: PHP and SQL not working. Keeps giving error

Posted 26 March 2013 - 12:08 PM

That's hideous. Read, learn, and then retry:
http://www.dreaminco...duction-to-pdo/
Was This Post Helpful? 0
  • +
  • -

#3 liaml7  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 3
  • Joined: 26-March 13

Re: PHP and SQL not working. Keeps giving error

Posted 26 March 2013 - 12:14 PM

View PostCTphpnwb, on 26 March 2013 - 12:08 PM, said:

That's hideous. Read, learn, and then retry:
http://www.dreaminco...duction-to-pdo/

Still dont understand...
Was This Post Helpful? 0
  • +
  • -

#4 liaml7  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 3
  • Joined: 26-March 13

Re: PHP and SQL not working. Keeps giving error

Posted 26 March 2013 - 12:31 PM

BUMP! PLEASE HELP!
Was This Post Helpful? -2
  • +
  • -

#5 Duckington  Icon User is offline

  • D.I.C Addict

Reputation: 170
  • View blog
  • Posts: 608
  • Joined: 12-October 09

Re: PHP and SQL not working. Keeps giving error

Posted 26 March 2013 - 12:44 PM

You need commas between the column values you are setting. But as CT said, you'd be much better off in the long run learning how to do your SQL queries via PDO (Prepared Data Objects) and Prepared Statements.
Was This Post Helpful? 0
  • +
  • -

#6 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3577
  • View blog
  • Posts: 10,442
  • Joined: 08-June 10

Re: PHP and SQL not working. Keeps giving error

Posted 26 March 2013 - 12:44 PM

other question, why are there 20 text fields?

besides that, there is a mismatch between your posted code and the error message’s code:
your code: text2='def' text3='def'
error code: text='def' text3='def'
you see a difference?

This post has been edited by Dormilich: 26 March 2013 - 12:44 PM

Was This Post Helpful? 0
  • +
  • -

#7 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6110
  • View blog
  • Posts: 23,670
  • Joined: 23-August 08

Re: PHP and SQL not working. Keeps giving error

Posted 26 March 2013 - 02:22 PM

I'd like to help but I can't see through the blood pouring out of my eyes.
Was This Post Helpful? 0
  • +
  • -

#8 darrenh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 26-March 13

Re: PHP and SQL not working. Keeps giving error

Posted 26 March 2013 - 07:20 PM

You need to separate the columns with commas " , ".

UPDATE table_name
SET column1=value, column2=value2,...
WHERE some_column=some_value



Read More: http://www.w3schools...ysql_update.asp
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1