SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict einSTein's Avatar
    Join Date
    Aug 2006
    Posts
    276
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    SQL syntax error

    this is my syntax
    Code MySQL:
    $kk=$session['user'];
    $sql="INSERT INTO user2 WHERE user = $kk (obj, Expr, pos, dob, comp, cnt, cert, Major, Grade, stPeri, cont2, skills, eng, fr, ge, span, other, jobT, empT)
    this is my error
    Error: You have an error in your SQL syntax near 'WHERE user = walaa (obj, Expr, pos, dob, comp, cnt, cert, Major, Grade, stPeri, ' at line 1
    i want to know whats wrong in my syntax an u must know that it raads the user well

  2. #2
    SitePoint Evangelist -T-'s Avatar
    Join Date
    Jun 2002
    Posts
    444
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Put "WHERE user = $kk" at the end

    Code:
    INSERT INTO user2 (obj, Expr, pos, dob, comp, cnt, cert, Major, Grade, stPeri, cont2, skills, eng, fr, ge, span, other, jobT, empT) WHERE user = $kk 


    Though, are the parts between the ( ) values or column names?

    if it is, you need to do it like this

    Code:
    INSERT INTO user2 VALUES ("obj", "Expr", "pos", "dob", "comp", "cnt", 
    "cert", "Major", "Grade", "stPeri", "cont2", "skills", "eng", "fr", "ge", "span", "other", "jobT", "empT") WHERE user = $kk 


    If it's not values but column names you aren't inserting any values into the table
    chrome is a wrapper that combines a browser with spyware

  3. #3
    SitePoint Addict einSTein's Avatar
    Join Date
    Aug 2006
    Posts
    276
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code MySQL:
    $sql="INSERT INTO user2 (obj, Expr, pos, dob, comp, cnt, cert, Major, Grade, stPeri, cont2, 
     
    skills, eng, fr, ge, span, other, jobT, empT) WHERE user = $kk
    VALUES
    ('$_POST[obj]','$Exp','$_POST[phel]','$_POST[cnam]', '$_POST[con]','$_POST
     
    [cer]','$_POST[Maj]','$_POST[Gd]','$_POST[stp]','$_POST[ctry]','$_POST[skills]','$_POST
     
    [Eng]','$_POST[FR]','$_POST[Ger]','$_POST[Spsh]','$_POST[other]','$_POST
     
    [Job]','$_POST[type]')";

    this is the error now
    Error: You have an error in your SQL syntax near 'WHERE user = walaa VALUES ('asdas','1','','', 'Egypt','','sdasdas','Pass','','' at line 1

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,341
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    if you are going to supply values, the correct syntax does not allow a WHERE clause at all

    check this page for more info

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    SitePoint Evangelist -T-'s Avatar
    Join Date
    Jun 2002
    Posts
    444
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Woha, now I feel stupid Mixed up update and insert for a sec

    If you are to update a field in the database, you can use where, but if you insert a new entry there is no need to match it to old entries, thus where gives you an error
    chrome is a wrapper that combines a browser with spyware


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
  •