Author Topic: SQL Statement Help!  (Read 180 times)

0 Members and 1 Guest are viewing this topic.

Offline matvespaTopic starter

  • Enthusiast
  • Posts: 68
    • View Profile
SQL Statement Help!
« on: March 16, 2010, 06:25:56 AM »
I thought there is nothing wrong with this SQL statement. Anyone can spot any mistake? Because i receive this error when i upload it onto my server

Quote
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 '' at line 1

Code: [Select]
$result = "Update auctiontransfer SET AuctionRate = " . $AuctionRate . "  where ID = " . $ID;

Offline Wolphie

  • Devotee
  • Posts: 681
  • Gender: Male
  • If you ask a question; please help answer one!
    • View Profile
Re: SQL Statement Help!
« Reply #1 on: March 16, 2010, 06:43:03 AM »
$AuctionRate is a string, so you need to surround it in quotes.

Code: [Select]
$result = "UPDATE auctiontransfer SET AuctionRate = '". $AuctionRate ."' WHERE ID = ". $ID;
Science without religion is lame. Religion without science is blind.

Offline PFMaBiSmAd

  • Guru
  • 'Insane!'
  • *
  • Posts: 14,588
  • In Coding, Automatic means you write code to do it
    • View Profile
Re: SQL Statement Help!
« Reply #2 on: March 16, 2010, 06:54:23 AM »
Echo $result so that you can see what is wrong with it. The error you got is typical of the numerical variable on the end of the query being empty.

If the AuctionRate column is a numeric data type, you would not want to enclose it in single-quotes in the query, especially if it is a DECIMAL data type as the single-quotes force a conversion to a FLOAT value, which can result in a floating point conversion error that the direct input of a DECIMAL data value would not have.
Signature: (not a comment about anything you posted unless specifically indicated)
Debugging step #1: To get past the garbage-out equals garbage-in stage in your code, you must check that the inputs to your code are what you expect.

Programming is just problem solving, but it is done in another language. You must learn enough of the programming language you are using to be able to read and write code.