Jump to content

Archived

This topic is now archived and is closed to further replies.

lamajlooc

SQL query syntax error

Recommended Posts

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 1

Here'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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 1
2.UPDATE uploads SET shown = 'y', showing = 'y' WHERE file_name = 1001626542.jpg
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 1

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.