You have an error in your SQL syntax; check the manual that corresponds to your MySQL

Discussion in 'Databases' started by JSellnau_TSCC, Aug 16, 2010.

  1. #1
    I keep getting a syntax error with my mySQL. I am expanding on a script that was written by someone else and just continued with the syntax that was already in place and fully functional. I just don't understand the fact that if the original syntax was functional and I followed the same syntax why all of a sudden it is not functional.

    
    $sql = "UPDATE `$areaname` set address = '$address', city = '$city',  state = '$state', rooms = '$rooms', zip = '$zip', rent = '$rent',  dateavailable = '$dateavailable', available = '$available', description =  '$description', leaseterms = '$leaseterms', filedescription1 =  '$filedescription1', filedescription2 = '$filedescription2',  filedescription3 = '$filedescription3', unit = '$unit' WHERE id =  '$id'";
    
    
    Code (markup):
    Thank you for your advice in advance.
     
    Last edited: Aug 16, 2010
    JSellnau_TSCC, Aug 16, 2010 IP
  2. aquilax

    aquilax Member

    Messages:
    126
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    33
    #2
    Looks just fine, check if the variables are set, especially $areaname, also dump the $sql variable and post it here if you can.
     
    aquilax, Aug 16, 2010 IP
  3. Thorlax402

    Thorlax402 Member

    Messages:
    194
    Likes Received:
    2
    Best Answers:
    5
    Trophy Points:
    40
    #3
    Looks good to me too. Make sure there are no quotes in the variables though. If there are then perform the function addslashes() on them to prevent them from messing up the sql statement.
     
    Thorlax402, Aug 16, 2010 IP
  4. JSellnau_TSCC

    JSellnau_TSCC Peon

    Messages:
    166
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Even after starting my modification over from scratch I am still getting the same error. I don't know where the problem is.

    Any ideas?

    Here is the error and $sql variable dump:
    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 ''listings-residential' set address = '1277 Rudy St', city = 'Onalaska', state = ' at line 1/
    /
    UPDATE 'listings-residential' set address = '1277 Rudy St', city = 'Onalaska', state = 'WI', zip = '54650', rent = '810.00', dateavailable = 'May 1, 2010', available = 'Yes', description = '*3mg High Speed Internet and 75 channel cable TV w/music channels INCLUDED in Rent *2 bedroom townhouse *Full bath 2nd floor *Large half-bath w/hookups main floor *Single car attached garage w/opener *Kitchen w/range, refrigerator, dishwasher and disposal *Gas heat,gas hot water. *Central A/C *Rear patio * Large ceramic foyer *Energy efficient sound proof construction ', leaseterms = '*One year Lease *Rent does not include utilities *Non-smoking *Pets at Landlord\'s discretion ', filename = '', unit = '#4' WHERE id = '125' 
    PHP:

    Thank you in advance for the help.
     
    JSellnau_TSCC, Aug 19, 2010 IP
  5. JSellnau_TSCC

    JSellnau_TSCC Peon

    Messages:
    166
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    hmmmm....

    nvm. I think I fixed it. It is was a punctuation error in using a variable to list the table name.
     
    JSellnau_TSCC, Aug 19, 2010 IP
  6. JSellnau_TSCC

    JSellnau_TSCC Peon

    Messages:
    166
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I have a second question for SQL syntax...

    Does the query look like the syntax is correct:

    $sql = "UPDATE `$areaname` set address = '$address', city = '$city', state = '$state', zip = '$zip', rent = '$rent', dateavailable = '$dateavailable', available = '$available', description = '$description', leaseterms = '$leaseterms', unit = '$unit', rooms = '$rooms', photodescription1 = '$photodescription1', photodescription2 = '$photodescription2', photodescription3 = '$photodescription3', $photoupload1, $photoupload2, $photoupload3 WHERE id = '$id'";
    
    PHP:
    (assuming that the $areaname, etc are all populated correctly)

    Thank you in advance for your help.
     
    JSellnau_TSCC, Aug 25, 2010 IP
  7. Thorlax402

    Thorlax402 Member

    Messages:
    194
    Likes Received:
    2
    Best Answers:
    5
    Trophy Points:
    40
    #7
    What's the deal with the end of the statement? "$photoupload1, $photoupload2, $photoupload3" isn't a valid UPDATE statement as far as I know.
     
    Thorlax402, Aug 25, 2010 IP
  8. JSellnau_TSCC

    JSellnau_TSCC Peon

    Messages:
    166
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Well it works for what I need it to do. What the variables are for is part a php based photo upload for 3 separate files (yes i know many have suggested jquery), the variables help me alter the query based on whether or not a file was changed from what is already listed int he db.
     
    JSellnau_TSCC, Aug 25, 2010 IP
  9. Thorlax402

    Thorlax402 Member

    Messages:
    194
    Likes Received:
    2
    Best Answers:
    5
    Trophy Points:
    40
    #9
    Ok, so if I'm following correctly then it sounds like the inclusion of those variables is to eliminate the need for a conditional statement checking to see if you need to upload each of three parts. What exactly is an example of something that the variables might be set too? Also, are there any errors with this syntax or are you just looking for feedback of some kind?
     
    Thorlax402, Aug 25, 2010 IP
  10. JSellnau_TSCC

    JSellnau_TSCC Peon

    Messages:
    166
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #10
    I appreciate your comments Thorlax402. I got it all worked out to handle what I need it too. If I have to go through and make new updates or add new features I am will correcting a lot of the syntax errors that might be there. Right now I am on a strict timeline and have to get things taken care of.
     
    JSellnau_TSCC, Aug 25, 2010 IP