I am having an issue saving images to a MYSQL database as a BLOB, I have been for a few days now, I have used several different tutorials and even though the code works with no errors returned, nothing actually get put in my database.

Here is my form to upload to my database, this is on a file called photo.php.

<form enctype="multipart/form-data" action="insert.php" method="post" name="changer">
<input name="MAX_FILE_SIZE" value="102400" type="hidden">
<input name="image" id="image" accept="image/jpeg" type="file">
<input value="Submit" type="submit">

Its very simple as its all I need for now, as you can see the action is taken from insert.php so here is the php code from insert.php which should save the image to my database.

include_once 'tables.php';

// Make sure the user actually
// selected and uploaded a file
if (isset($_FILES['image']) && $_FILES['image']['size'] > 0) {

      // Temporary file name stored on the server
      $tmpName  = $_FILES['image']['tmp_name'];

      // Read the file
      $fp      = fopen($tmpName, 'r');
      $data = fread($fp, filesize($tmpName));
      $data = addslashes($data);

      // insert into our database.
      $result = mysql_query("INSERT INTO tbl_images ('image') VALUES ('$data')");

      // Print results
      print "Thank you, your file has been uploaded.";


here is the code for my table which is also very simple for now

CREATE TABLE tbl_images (
id tinyint(3) unsigned NOT NULL auto_increment,
image blob NOT NULL,

This code includes tables.php as it has the access details for the database.

Was hoping someone could help me find the issue to why my images won't save to my database.


6 Years
Discussion Span
Last Post by AdriftUniform

I have managed to fix this, I realised that I was not submitting a NULL value into the database for field 'id'.

Sorry for any inconvenience.

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.