1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

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

Discussion in 'MySQL' started by lost, Nov 1, 2005.

  1. #1
    I'm getting the following error and have no idea what is wrong:

    "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 'use, location, guardian, dateremoved, expectedreturndate, actual"

    Here is my line of code:
    	 $query = "INSERT INTO cca_assembly(description, partno, itemno, serno, barcode, manu, manupartno, manuserno, use, location, guardian, dateremoved, expectedreturndate, actualreturndate, notes) VALUES ('$desc', '$pno', '$ino', '$sno', '$brcd', '$mnu', '$mnupno', '$mnusno', '$iuse', '$loc', '$grdn', '$datermvd', '$exreturndate', '$actreturndate', '$ntshstry')";
    
    Code (markup):
     
    lost, Nov 1, 2005 IP
  2. dct

    dct Finder of cool gadgets

    Messages:
    3,132
    Likes Received:
    328
    Best Answers:
    0
    Trophy Points:
    230
    #2
    use is a reserved word you need to wrap it in backticks (Ithink that's what their called) like this

    
    INSERT INTO cca_assembly 
        (description, partno, itemno, serno, barcode, manu, manupartno,
         manuserno, `use`, location, guardian, dateremoved, expectedreturndate,
         actualreturndate, notes) 
    VALUES 
        ('$desc', '$pno', '$ino', '$sno', '$brcd', '$mnu', '$mnupno', '$mnusno',
        '$iuse', '$loc', '$grdn', '$datermvd', '$exreturndate', '$actreturndate', 
        '$ntshstry')
    
    Code (sql):
     
    dct, Nov 1, 2005 IP
  3. elkiwi

    elkiwi Active Member

    Messages:
    536
    Likes Received:
    34
    Best Answers:
    0
    Trophy Points:
    68
    #3
    Also make sure that you are using addslashes if those variables are coming from a form as that will cause errors with things like " elkiwi's "
     
    elkiwi, Nov 1, 2005 IP
  4. lost

    lost Peon

    Messages:
    144
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks guys, i just changed the name, the error is now gone, however i'm now getting this:

    Unknown column 'usesearchtype' in 'field list'
     
    lost, Nov 1, 2005 IP
  5. dct

    dct Finder of cool gadgets

    Messages:
    3,132
    Likes Received:
    328
    Best Answers:
    0
    Trophy Points:
    230
    #5
    Can you post the new SQL as I can't see the 'usesearchtype' in your original code.
     
    dct, Nov 1, 2005 IP
  6. lost

    lost Peon

    Messages:
    144
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    $query = "INSERT INTO cca_assembly(description, partno, itemno, serno, barcode, manu, manupartno, manuserno, usesearchtype, locsearchtype, grdnsearchtyp, dateremoved, expectedreturndate, actualreturndate, notes) VALUES ('$desc', '$pno', '$ino', '$sno', '$brcd', '$mnu', '$mnupno', '$mnusno', '$iuse', '$loc', '$grdn', '$datermvd', '$exreturndate', '$actreturndate', '$ntshstry')";
    Code (markup):
     
    lost, Nov 1, 2005 IP
  7. dct

    dct Finder of cool gadgets

    Messages:
    3,132
    Likes Received:
    328
    Best Answers:
    0
    Trophy Points:
    230
    #7
    Does the column usesearchtype even exist?
     
    dct, Nov 1, 2005 IP
  8. lost

    lost Peon

    Messages:
    144
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Sorry my bad, i forgot to change use in the database....

    Thanks again guys.
     
    lost, Nov 1, 2005 IP
  9. yangyang

    yangyang Banned

    Messages:
    757
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Well, even the smartest of programmers make stupid mistakes. :)

    This checklist might be helpful for avoiding such mistakes.
     
    yangyang, Jan 15, 2009 IP