Jump to content


Photo

SQL query syntax error


  • Please log in to reply
4 replies to this topic

#1 lamajlooc

lamajlooc
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 28 October 2006 - 10:58 PM

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.

#2 pendelton

pendelton
  • Members
  • PipPip
  • Member
  • 20 posts
  • LocationUK

Posted 28 October 2006 - 11:14 PM

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.


#3 lamajlooc

lamajlooc
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 29 October 2006 - 12:56 AM

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

#4 pendelton

pendelton
  • Members
  • PipPip
  • Member
  • 20 posts
  • LocationUK

Posted 29 October 2006 - 01:00 AM

Try

$query = "UPDATE uploads SET shown = 'y', showing = 'y' WHERE file_name = '{$row[0]}'";

#5 lamajlooc

lamajlooc
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 30 October 2006 - 10:23 AM

Yeah, I saw that the minute I added the code you wanted.  Thanks for your help man.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users