views:

19

answers:

1

My code:

$fileid = $_GET['imgid'];
$fileid = (int)$fileid; //id is int type in photos table

require 'database.php';

//get the image sourc name

$q = "SELECT src form photos WHERE id='$fileid'";
$result = $mysqli->query($q) or die(mysqli_error($mysqli));

if ($result) 
{
    $row = $result->fetch_object();
    $filename = $row->src;

ERROR: 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 'photos WHERE id='12'' at line 1

+6  A: 

You have FROM misspelled. Try:

$q = "SELECT src FROM photos WHERE id='$fileid'";

In addition, while not related to this syntax error, note that your code appears to be vulnerable to SQL Injection.

Daniel Vassallo
how come it is vulnerable?
Col. Shrapnel
it only appears to be, until you look at line 2 ;)
Mchl
@Col: Oops, you're right. Didn't notice it's being cast to an `int`.
Daniel Vassallo
@Col. Yep the cast to int will prevent that whether by accident or design.
Martin Smith
Yep, my bad :) ... fixed the answer.
Daniel Vassallo