SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: Help with query

  1. #1
    SitePoint Zealot fredep57's Avatar
    Join Date
    Aug 2009
    Location
    Pacific Northwest
    Posts
    137
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help with query

    I have a database for my classified ads for our club. I have the structure as follows:

    Classified_ID int(11)
    Name varchar(40)
    Address1 varchar(35)
    Address2 text
    City varchar(35)
    State varchar(3)
    ZipCode int(5)
    PhoneNumber varchar(12)
    Member int(1)
    Ad_Type varchar(10)
    Subject_Title text
    Ad_Content text
    Date_Submitted date
    Duration int(2)
    Active int(1)
    adEmail varchar(35) Yes

    Now, I have a query to insert into this database, but it fails and I cannot figure out why.

    query to insert:
    INSERT INTO Classified ('Name', 'Address1', 'City', 'State', 'ZipCode', 'adEmail', 'PhoneNumber', 'Member', 'AdType', 'Ad_Content', 'Date_Submitted', 'Duration', 'Active') VALUES ('richerd', '9876', here', 'WA', '99217', 'address@email.com', '508-555-1212', '0', 'Wanted', ' wanting something', '04-16-2012', '3', 1)

    Failure message:
    Data did not get inserted into Participant table - 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 ''Name', 'Address1', 'City', 'State', 'ZipCode', 'adEmail', 'PhoneNumber', 'Membe' at line 1

    Please let me know what I am doing wrong.

    Oh, PHP version is 5.2.17 just in case you were going to ask...

    E

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,017
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    the relevant syntax is
    Code:
    INSERT INTO tablename ( list of columns ) VALUES ( list of values )
    instead of a list of columns, you have a list of strings

    mysql's backtick, the spawn of the devil, pwns yet another developer!!
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Zealot fredep57's Avatar
    Join Date
    Aug 2009
    Location
    Pacific Northwest
    Posts
    137
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah, yes. Used the wrong "marker".

    However, begs the question, are the backticks really needed? And, why does phpmyadmin put them in? Just to confuse us that learn by "example"??

    Thanks and it is now working.

    E

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,017
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    phpmyadmin puts them in because you didn't turn that option off

    backticks are not needed if you remember never to put a special character (like a space or number sign) into a table or column name, or use a reserved word (like order) for a table or column name
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •