Deno Posted April 11, 2004 Posted April 11, 2004 I get this error when trying to retreive data on one of my pages: "Error when querying the database: 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 '' at line 1" I don't get why this happening, cause it works on my other pages, and the php code structure is EXACTLY the same too! I'm guessing it has something to do with my sql table. Please help. Mad!!! Quote
borfast Posted April 12, 2004 Posted April 12, 2004 Deno, what's the SQL query you're trying to execute? Quote
Deno Posted April 12, 2004 Author Posted April 12, 2004 Here's a copy & paste of my code: $Query = "select * from cd_review where cd_id = $article"; $Result = mysql_query($Query,$Link) or die("Error when querying the database: ".mysql_error()); if(mysql_num_rows($Result) == 0) { print("No results to display."); } while ($Row = mysql_fetch_array($Result)) { print("<font size=5><i>$Row[title]</i></font><p>"); print("$Row[review]"); } mysql_close($Link); It's the same as my other pages, except the table name is different. Quote
DarqFlare Posted April 12, 2004 Posted April 12, 2004 I can't find anything... 2 suggestions: 1) Take out the spaces before and after the = equal sign in the query. 2) Put a space between the 2 arguments to the mysql_query() function. Quote
MikeJ Posted April 12, 2004 Posted April 12, 2004 $Query = "select * from cd_review where cd_id = $article";$Result = mysql_query($Query,$Link) or die("Error when querying the database: ".mysql_error()); Another thing I would be checking is the contents of $article. Quote
borfast Posted April 12, 2004 Posted April 12, 2004 (edited) Yep, I agree with Mike, that's probably where the problem is, because that's the only part of the query that we can't see in it's final form. Other than that, I don't see any error. I prefer to use all caps for the SQL statements but I don't think it makes a difference. Try adding a bit more of error checking to the mysql_query() line, like this: >$Result = mysql_query($Query,$Link) or die("Query: $Query<br /><br />Error when querying the database: ".mysql_error()); That way you'll be able to see the whole query and check that $article variable to see if it's ruining the whole thing. Hope it helps Edited April 12, 2004 by TCH-Raul Quote
Deno Posted April 18, 2004 Author Posted April 18, 2004 Hey y'all, I'm still having problems.... (I've been away for the past few days btw)... I decided to give it a test, by printing the $article variable to see if it even carried the $article number over, and it prints nothing on the next page. What's my problem? Quote
Deno Posted April 18, 2004 Author Posted April 18, 2004 Ok, here's what I'm trying to do.... go to http://www.starryconstellation.com, then scroll down to the links that say "CD Review" under Jennifer Marks or Ben Arthur. When you click on those links, it goes to the cdreview.php page, looking like this cdreview.php?artist=9 or 10. It goes to the sql db and queries this: $Query = "select * from cd_review where cd_id = $article"; and then displays the info... but somehow, it doesn't read the $article!! But yet it works on the rest of my pages, like the TV and movie reviews. The code's EXACTLY the same!! please please help! Quote
btrfld Posted April 18, 2004 Posted April 18, 2004 This may be ridiculously simple, or maybe I'm just missing something (entirely possible), but it seems to me that you're passing the wrong variable name to the .php page. it goes to the cdreview.php page, looking like this cdreview.php?artist=9 or 10. It goes to the sql db and queries this: $Query = "select * from cd_review where cd_id = $article"; Shouldn't the arguments be the same? Either ....php?article=9 or ... cd_id=$artist My 2p. Hope it helps. Jim Quote
Deno Posted April 18, 2004 Author Posted April 18, 2004 You know what Jim? You are sooooo right! ARRRGHHH!! How stupid of me! getting $artist and $article mixed up!! man, how can I not see that?!?! Thanks for noticing that! Appreciate it a lot! Rock Sign Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.