Hi Everyone, I am new to PDO PHP - I am getting to grips with the insert statements with bind_param.

What I am a bit confused about is how to update a table where id = $var

I have an image upload script that works fine, as it uploads the image to the server location.
What I am trying to do is update the users db table with the location of the image on the server.

Here is my attemp, the strange thing is, Im not seeing any error messages, but the table field is not being update.
Any help would be great.

    $dbtype     = "mysql";
    $dbhost     = "dbh";
    $dbname     = "dbn";
    $dbuser     = "dbu";
    $dbpass     = "dbp";    
    // database connection
    $conn = new PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass);   
    // new data
    $img = '$resized_file';
    $author = '$authorid';
    // query
    $sql = "UPDATE table 
            SET image=?,
            WHERE id=?";
    $q = $conn->prepare($sql);
3 Years
Discussion Span
Last Post by pritaeas

Here's a code snippet showing you how to check for errors.

Perhaps you need to explicitly specify the type if you are inserting into a blob.

Edited by pritaeas


Hi, Im not inserting into a blob, I am trying to insert the image file name? as a string...


Got it to work by doing the following -

    $img = "$resized_file";
    $author = "$authorid";
    // query
    $sql = "UPDATE table SET image = ? WHERE id = ?";
    $q = $conn->prepare($sql);

Just incase someone else is having the same issues... Hope it helps


Oh, table is a reserved word, so if that's really the name of your table, surround it with backticks.

Ah, I missed that comma too...

Edited by pritaeas

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.