lamajlooc Posted October 28, 2006 Share Posted October 28, 2006 I have a script that selects files from a DB and displays them side by side whenever it's run. I get an error whenever it runs the following code though and I can't figure out what's wrong with my syntax.The error is: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 'jpg' at line 1Here's the code:// Select the new challenger randomly from the DB and reassign values accordingly $query = "SELECT file_name FROM uploads WHERE file_name <> '{$winner_fn}' AND file_name <> '{$loser_fn}' AND shown <> 'y' ORDER BY RAND() LIMIT 1"; $result = mysql_query($query) or die(mysql_error()); if ($row = mysql_fetch_row($result)) { $query = "UPDATE uploads SET shown = 'y', showing = 'y' WHERE file_name = {$row[0]}"; $result = mysql_query($query) or die(mysql_error()); $challenger_fn = $row['0']; echo "$challenger_fn"; } else { echo "<p>Could not select challenger!</p>"; }Thanks. Quote Link to comment Share on other sites More sharing options...
pendelton Posted October 28, 2006 Share Posted October 28, 2006 Try adding the following lines:After the line $query = "SELECT file_name FROM uploads...Add print "1. $query<BR>\n";After the line $query = "UPDATE uploads...Add print "2. $query<BR>\n";Let me know what prints out. Quote Link to comment Share on other sites More sharing options...
lamajlooc Posted October 29, 2006 Author Share Posted October 29, 2006 Hi,This is what is returned:1.SELECT file_name FROM uploads WHERE file_name <> '632755314.jpg' AND file_name <> '1074829277.jpg' AND shown <> 'y' ORDER BY RAND() LIMIT 12.UPDATE uploads SET shown = 'y', showing = 'y' WHERE file_name = 1001626542.jpgYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'jpg' at line 1 Quote Link to comment Share on other sites More sharing options...
pendelton Posted October 29, 2006 Share Posted October 29, 2006 Try$query = "UPDATE uploads SET shown = 'y', showing = 'y' WHERE file_name = '{$row[0]}'"; Quote Link to comment Share on other sites More sharing options...
lamajlooc Posted October 30, 2006 Author Share Posted October 30, 2006 Yeah, I saw that the minute I added the code you wanted. Thanks for your help man. Quote Link to comment Share on other sites More sharing options...
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.