MySQL error, please help!

Discussion in 'MySQL' started by nQQb, Jan 8, 2008.

  1. #1
    I get the following error: Invalid query: 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 'ORDER BY f_dateadded DESC' at line 1

    I don't know what I'm doing wrong. Could someone please look at the code below. I'm using GoDaddy hosting and getting the error.

    Thanks for any help you could offer.

    <?
    
    	$conn=mysql_connect($dbhost, $dbuser, $dbpass);
    	mysql_select_db($dbname) or die ("Unable to connect to MySQL");
    	// print "Connected to MySQL"; 
    	
    	$qresult2 = mysql_query("SELECT * FROM t_favs WHERE u_id=$userID ORDER BY f_dateadded DESC");
    	
    	if (!$qresult2) {
       die('Invalid query: ' . mysql_error());
    	}
    	
    	while ($line2 = mysql_fetch_assoc($qresult2)){ 
    	
    	$qresult = mysql_query("SELECT * FROM t_media WHERE m_id=".$line2["m_id"]." ORDER BY m_id DESC LIMIT 1");
    	
    	if (!$qresult) {
       die('Invalid query: ' . mysql_error());
    	}
    		
    	while ($line = mysql_fetch_assoc($qresult)){
    	?>	
    
    <? include("showitem.php"); ?>
    
    <? }
    	}
    
    mysql_close($conn);
    ?>
    PHP:

     
    nQQb, Jan 8, 2008 IP
  2. sunnyverma1984

    sunnyverma1984 Well-Known Member

    Messages:
    342
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    120
    #2
    what is the mysql version on your host?
     
    sunnyverma1984, Jan 8, 2008 IP
  3. zybron

    zybron Peon

    Messages:
    199
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    My guess is this line:

    You probably want to look like:

    $qresult2 = mysql_query("SELECT * FROM t_favs WHERE u_id=".$userID." ORDER BY f_dateadded DESC");
    PHP:
    So that the $userID is actually parsed.
     
    zybron, Jan 8, 2008 IP
  4. HuggyStudios

    HuggyStudios Well-Known Member

    Messages:
    724
    Likes Received:
    20
    Best Answers:
    26
    Trophy Points:
    165
    #4
    You can do it like,

    
    
    mysql_query("SELECT * FROM `table` WHERE u_id = '$id' ORDER BY f_dateadded DESC") or die (mysql_error());
    
    
    PHP:
     
    HuggyStudios, Jan 8, 2008 IP
  5. nQQb

    nQQb Active Member

    Messages:
    332
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #5
    Hi Zybon, I tried that but same error :(
    sunny, the database is 4.1 but in godaddy phpinfo, i see client api 5.x.x
     
    nQQb, Jan 8, 2008 IP
  6. zybron

    zybron Peon

    Messages:
    199
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Does $userID actually have a value before it is being used in that query? I assumed so, but if that code is everything in the script, that's probably the issue.
     
    zybron, Jan 8, 2008 IP
  7. nQQb

    nQQb Active Member

    Messages:
    332
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #7
    well, it checks whether the use is logged in and if not, they get to signup page. this is the website: metropolizonline [dot] com and when you click on myaccount, you will see this error.
     
    nQQb, Jan 8, 2008 IP
  8. chrissyj

    chrissyj Peon

    Messages:
    56
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #8
    OK, try this:

    $qresult2 = mysql_query("SELECT * FROM t_favs WHERE u_id='$userID' ORDER BY f_dateadded DESC"

    If the error goes away, then you have a code bug. The variable "$userID" is empty or undefined, which without the ' marks surrounding the variable will cause an error. This code probably won;t work right, but the SQL error will be gone.

    Also, check the spelling and capitalization of "f_dateadded" on the line to make sure it is correct.

    PM me if you need more info.
     
    chrissyj, Jan 8, 2008 IP
  9. nQQb

    nQQb Active Member

    Messages:
    332
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #9
    well the error is gone but blank page now...i installed the script on my server and it worked fine...it is working on pokerfinder dot com but on godaddy it wont work...i think its php and mysql version conflict.
     
    nQQb, Jan 8, 2008 IP
  10. kendo1979

    kendo1979 Peon

    Messages:
    208
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #10
    where did you get $userID from? is it passed by form? is the status of register_global on the php.ini between your old and new server the same?
     
    kendo1979, Jan 9, 2008 IP
  11. jigolo

    jigolo Peon

    Messages:
    312
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #11
    try to check the MySQL version from your host if their are the same version..:)
     
    jigolo, Jan 10, 2008 IP