Thread: SQL error 1064

Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    10
    Rep Power
    0

    Exclamation SQL error 1064


    I have a piece of code which is written to call record from a MySQL database. everything is right and the connection goes through but when i put this statment into PHP myadmin in the SQL part of it;

    The statement is;
    PHP Code:
    $query "SELECT *  MATCH (firstname, lastname) AGAINST ('".$trimm."') AS score FROM Trophies WHERE MATCH (firstname, lastname) AGAINST ('+".$trimm."') ORDER BY score DESC"
    but the error i am getting is;
    error 1064 - #1064 - 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 '$query = "SELECT * MATCH (firstname, lastname) AGAINST ('".$trimm."') AS score ' at line 1

    I have another line similar which recieves the same error

    What have i tried;
    - I tried putting single quotes instead of double quotes
    - I tried putting no quotes
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Mar 2008
    Posts
    1,934
    Rep Power
    379
    Don't put the WHOLE line into phpmyadmin, just the bit in quotation marks!

    It still won't be right, but you'll be one step nearer...
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    10
    Rep Power
    0
    Originally Posted by cafelatte
    Don't put the WHOLE line into phpmyadmin, just the bit in quotation marks!

    It still won't be right, but you'll be one step nearer...
    cheers
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Mar 2008
    Posts
    1,934
    Rep Power
    379
    ...just the bit in quotation marks!
    ...or, more accurately, the output of...

    echo $query;
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    10
    Rep Power
    0
    thanks but its giving me the same error message,do you how to fix it by any chance??
  10. #6
  11. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,363
    Rep Power
    4281
    Originally Posted by bobskiny
    thanks but its giving me the same error message,do you how to fix it by any chance??
    can you please show the exact code you passed to mysql
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    10
    Rep Power
    0
    how do you mean, the part i wrote in my orginal entry was the part i copied into the sql part of phpmyadmin and then i got that 1064 error.

    but if you are asking me for the rest of my code then i can give you that aswell??

    Thank you for helping me
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Mar 2008
    Posts
    1,934
    Rep Power
    379
    No.

    We just want the output of:

    echo $query;
  16. #9
  17. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,363
    Rep Power
    4281
    Originally Posted by bobskiny
    the part i wrote in my orginal entry was the part i copied into the sql part of phpmyadmin
    we've been trying to tell you that mysql cannot handle php code

    if you submitted this to phpmyadmin --
    Code:
    $query = "SELECT *  MATCH (firstname, lastname) AGAINST ('".$trimm."') AS score FROM Trophies WHERE MATCH (firstname, lastname) AGAINST ('+".$trimm."') ORDER BY score DESC";
    then mysql is gonna barf immediately on that red part

    mysql can only handle pure sql, which is the SELECT statement after all php variables in it have been substituted

    which is why we keep asking you to run your php code and put in the echo statement so that you can see the $query sql string

    then that $query sql string is what you copy/paste into phpmyadmin
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    10
    Rep Power
    0
    This helps, thanks i can see where the error is being caused better.

    the error i am getting now is the same but shows a more specific part of the code;

    #1064 - 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 'MATCH (firstname, lastname) AGAINST ('".$trimm."') AS score FROM Trophies WHERE ' at line 1

    does anyone know the problems now please?
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Mar 2008
    Posts
    1,934
    Rep Power
    379
    Yeah, you're STILL NOT SHOWING US THE QUERY - the thing you pasted into phpmyadmin!!!!!!!!!!!!!!!!!!!!!!!!!!

    (although this particular problem is a missing comma)
  22. #12
  23. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    10
    Rep Power
    0
    sorry dont go mad at me please but i dont knwo what you mean, see i am new to this;

    this is what i think you mean but i dont know;

    PHP Code:
    [PHPNET]foreach ($trimmed_array as $trimm){
        
    $query "SELECT *  MATCH (firstname, lastname) AGAINST ('".$trimm."') AS score FROM Trophies WHERE MATCH (firstname, lastname) AGAINST ('+".$trimm."') ORDER BY score DESC"
        
    $numresults=mysql_query ($query); 
        
    $row_num_links_main =mysql_num_rows ($numresults); [/PHPNET
    hope this is what you want this is the whole block thankyou for participating with me
  24. #13
  25. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,363
    Rep Power
    4281
    could you do me a favour please

    describe, in your own words, the difference between running a query from inside your php code, versus running a query through the sql window of phpmyadmin

    what is the key difference between those two methods?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
  26. #14
  27. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    10
    Rep Power
    0
    well i had this code which had was not executing properly and kept giving me an error saying resource needed, boolean given whihc was on line 52 whihc was the last line in my previous entry;
    $row_num_links_main =mysql_num_rows ($numresults)

    and i saw a youtube video which said the problem was not actualy with this line and was infact with the line i put before;
    $query = "SELECT * , MATCH (firstname, lastname) AGAINST ('".$trimm."') AS score FROM Trophies WHERE MATCH (firstname, lastname) AGAINST ('+".$trimm."') ORDER BY score DESC";

    and he said to put this into phpmyadmin on the sql tab and then it will show you what the mistake is so i did this and still couldnt figure out what the mistake was and that is why i asked on this forum

    the only difference i see between the two methods is that the phpmyadmin gives you more of a clue as to where the mistake is, but i just really need some help because i dont really have clue about what i am doing. i dont have the time to learn the language properly right now as i did HTML and CSS
  28. #15
  29. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,363
    Rep Power
    4281
    i will say it one last time...

    this is not sql --
    Code:
    $query = "
    that's php code and mysql will barf on it

    whatever you paste into the phpmyadmin sql window has to be sql only -- no php code

    also, we've asked you a couple of times to put an echo statement into your php code so that you can see for yourself the query string that your php code is building

    when you echo out that php string, it will start with the mysql keyword SELECT and that's what you would then copy/paste into phpmyadmin's sql window to test
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo