Jump to content

SQL query syntax error


lamajlooc

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.