Jump to content

[SOLVED] Update image in database


herghost

Recommended Posts

Hi all,

 

I currently have this script which uploads an image to a database:

 

<?php
session_start();

include('include/database.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'];  
       $userid = $_SESSION['SESS_USERID'];
      // Read the file 
      $fp      = fopen($tmpName, 'r');
      $data = fread($fp, filesize($tmpName));
      $data = addslashes($data);
      fclose($fp);
      

      // Create the query and insert
      // into our database.
  
  $sql = mysql_query("SELECT * FROM bandpic WHERE userid = '$userid'");
if(mysql_num_rows($sql) == 0)
{
      $query = "INSERT INTO bandpic
   (userid, image)
   values
   ('$userid','$data')";
   
}
else
$query = "UPDATE bandpic SET 
userid = '$userid,
image = '$data";

}
   
     $result = mysql_query($query);
    
   //Check whether the query was successful or not
   if($result) {
      header("location: member_home.php");
      exit();
   }else {
      die(mysql_error());
      
   }
   
   ?>

// Close our MySQL Link
mysql_close($con);
?>  

 

However, if an image is already present I get this 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 'GIF89a\0D\0�\0\0\0\0\0���C����������������������������������������������������' at line 2

 

Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/153576-solved-update-image-in-database/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.