"You have an error in your SQL syntax"

Discussion in 'MySQL' started by unlisted80, Oct 5, 2006.

  1. #1
    what this mean?


     
    unlisted80, Oct 5, 2006 IP
  2. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #2
    It means you have an error in your SQL syntax near the quoted part.

    Not sure how else to put it.

    Perhaps in more straight forward terms: You have buggered code. It's kaputt, not working. Bad Query.
     
    T0PS3O, Oct 5, 2006 IP
  3. Cotillion

    Cotillion Peon

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Simply use mysql_error function while debugging your applications:

    http://www.php.net/manual/en/function.mysql-error.php
     
    Cotillion, Oct 5, 2006 IP
  4. aRo`

    aRo` Peon

    Messages:
    141
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    my best guess is you are giving a string in your WHERE tag where the field is an Integer in mysql

    fk_user_id='1''
     
    aRo`, Oct 6, 2006 IP
  5. unlisted80

    unlisted80 Peon

    Messages:
    644
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #5
    i got this in the sql
    and i got this in the table:

    is the int (10) give me a problem?
     
    unlisted80, Oct 6, 2006 IP
  6. rosytoes

    rosytoes Peon

    Messages:
    230
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #6
    You just showed us the default query in phpmyadmin. What is it you are trying to do? If you just want to show all user details just use
    select * from user_details
    Code (markup):
     
    rosytoes, Oct 7, 2006 IP
  7. unlisted80

    unlisted80 Peon

    Messages:
    644
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #7
    this is my user_detail table

     
    unlisted80, Oct 7, 2006 IP
  8. sacx13

    sacx13 Active Member

    Messages:
    438
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    58
    #8
    Just show the sql query ...

    Regards
     
    sacx13, Oct 7, 2006 IP
  9. blade_922

    blade_922 Well-Known Member

    Messages:
    396
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    110
    #9
    Post the Code and we'll take a look,.
     
    blade_922, Oct 7, 2006 IP
  10. rb3m

    rb3m Peon

    Messages:
    192
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #10
    aRo had it right, fk_user_id is a number field, but your SQL query is requesting text (the ' around the 1 tell SQL to treat it as text).

    Just remove the single quotes from your query and it should work.
     
    rb3m, Oct 7, 2006 IP
  11. JEET

    JEET Notable Member

    Messages:
    3,832
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #11
    I think you have missed the "FIELD" name in the query you showed.
    $q="SELECT * FROM `user_details` WHERE fk_user_id='1'";
    should be the query.
    Bye:)
     
    JEET, Oct 7, 2006 IP
  12. SoKickIt

    SoKickIt Active Member

    Messages:
    305
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    70
    #12
    It would work with and without those quotes. It doesn't matter if it's a number or not.
     
    SoKickIt, Oct 7, 2006 IP
  13. unlisted80

    unlisted80 Peon

    Messages:
    644
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #13
    so i change this

    To THis

    i am not good at this :)
     
    unlisted80, Oct 7, 2006 IP
  14. rb3m

    rb3m Peon

    Messages:
    192
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #14
    No, it should be:
    SELECT * FROM user_details WHERE fk_user_id=1;

    You need something to compare after the WHERE, in this case the fk_user_id field.

    Wanna bet? ;)
     
    rb3m, Oct 7, 2006 IP
  15. JEET

    JEET Notable Member

    Messages:
    3,832
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #15
    Yes, that should be the query. Additionally, I think instead of fk_user_id, your script must be selecting from some other field like state or country etc.
    Because if you use fk_user_id, you will keep selecting only the very first record all the time. SELECTING from some other field will give you more records and probably that's what your script must do.
    Bye:)
     
    JEET, Oct 8, 2006 IP
  16. SoKickIt

    SoKickIt Active Member

    Messages:
    305
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    70
    #16
    SELECT * FROM user_details WHERE fk_user_id=1;
    SELECT * FROM user_details WHERE fk_user_id='1';
    SELECT * FROM user_details WHERE 1;
    SELECT * FROM user_details WHERE 1=1;
    SELECT * FROM user_details;

    All those queries work.
     
    SoKickIt, Oct 8, 2006 IP
  17. unlisted80

    unlisted80 Peon

    Messages:
    644
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #17
    I go to phpmyadmin then i selected user detail then i selected fk_user_id and paste this in and click go right?


    :confused: :confused: :confused:
     
    unlisted80, Oct 8, 2006 IP
  18. rb3m

    rb3m Peon

    Messages:
    192
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #18
    Actually you could just click where it says SQL after you've selected your database, then paste it in the box and click "GO".

    Also check the SQL tutorials at W3 schools. www .w3schools .com
     
    rb3m, Oct 8, 2006 IP