SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: MYSQL Query

  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2002
    Location
    Illinois
    Posts
    55
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    MYSQL Query

    I am going nuts here. I am trying to do a basic insert query, like I've done a million times before and its not working. Here is a snip of code:

    $query = "INSERT INTO lm SET
    class = '$_POST[class]',
    desc = '$_POST[desc]',
    stock = '$_POST[stock]',
    color = '$_POST[color]',
    size = '$_POST[size]',
    retail = '$_POST[retail]',
    cost = '$_POST[cost]',
    minorder = '$_POST[minorder]',
    avail = '$_POST[avail]',
    comm = '$_POST[comm]',
    thumb = '$_POST[thumb]',
    image = '$_POST[image]' ";

    if (@mysql_query($query)) {
    echo( "<P>The Record for <B>$_POST[desc]</b> has been added.</P>");
    }

    The error I keep getting is:
    You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use

    Thanks in advance.
    CC
    -- Hit any key to continue. "Where's the any key?" --

  2. #2
    Just Blow It bronze trophy
    DaveMaxwell's Avatar
    Join Date
    Nov 1999
    Location
    Mechanicsburg, PA
    Posts
    7,263
    Mentioned
    115 Post(s)
    Tagged
    1 Thread(s)
    Syntax error usually means one of two things:
    1) You've got a numeric field receiving a string value (ie the value is surrounded by quotes)
    2) You've got a field name that is a reserved word.
    Dave Maxwell - Manage Your Site Team Leader
    My favorite YouTube Video! | Star Wars, Dr Suess Style
    Learn how to be ready for The Forums' Move to Discourse

  3. #3
    Santos L Halper Zenith's Avatar
    Join Date
    May 2002
    Location
    Finland
    Posts
    641
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    INSERT INTO table (field1, field2) VALUES ('value1', 'value2');

    UPDATE table SET field1='value1', field2='value2'

    You've tried to mix update and insert there, try to decide which one ;-)

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,247
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    actually, zenith, while it is certainly not standard, that syntax is supported in mysql

    it's likely the desc column name as dave suggested -- desc is a reserved word

    rudy
    http://r937.com/

  5. #5
    SitePoint Enthusiast
    Join Date
    Aug 2002
    Location
    Illinois
    Posts
    55
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ahh thank you Rudy...

    I changed desc to descr in all of my code and it works like a champ. Thanks

    Actually I didn't know my instert query wasn't standard. Mr. Yank has used the way I have shown in his book so thats the way I learned. If the other way is standard, I guess I will have to re-teach myself how to insert with mySQL.

    Thanks again.
    -- Hit any key to continue. "Where's the any key?" --


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
  •