Simple MySQL query giving me a syntax error

Ahoy hoy!

Got a problem with a really really simple query to my MySQL server, and it’s just not having any of what I try. Been out of the game a while but I can’t see how this has tripped me up!

The code is

[php]$link = mysql_connect(‘db2885.oneandone.co.uk’, ‘dbo349707729’, ‘spartans’);
if (!$link) {die('Could not connect: ’ . mysql_error());}

$query = sprintf(“SELECT photo FROM djs WHERE djid=%s”, $_GET[‘id’]);

$result = mysql_query($query, $link);

if(!$result) { $message = 'Invalid query: ’ . mysql_error() . “
\n” . 'Whole query: ’ . $query; die($message); }

$row = mysql_fetch_assoc($result);
header(“Content-type: image/jpeg”);
print $row[‘photo’];[/php]

I was getting an error telling my syntax was wrong in the query near " ‘djs’ WHERE ‘djid’=‘1’ ", and so I tried removing the apostrophes and now I’m getting:

Invalid query: No database selected Whole query: SELECT photo FROM djs WHERE djid=1

Literally the only change required to go from “no database selected” to “syntax error” is the placement of apostrophes around the field and table names.

Any idea what is going on here?

Cheers,

Adam

Aaaand password changed :stuck_out_tongue:

I r a tard for a second there -_-

Sponsor our Newsletter | Privacy Policy | Terms of Service