Jump to content

Error in uploading Image in Database


tahakirmani

Recommended Posts

I am trying to save images in my database from HTML form. I have written PHP code to accomplish this task. Its giving me the following error message,and not inserting data in the database. Kindly check it.
Here i am sharing a excerpt from my code.
I am using BLOB for image.
 
   
 /*-------------------
    IMAGE QUERY
    ---------------*/
    
    
        $file    =$_FILES['image']['tmp_name'];
        
        
        if(!isset($file))
        {
            echo 'Please select an Image';
            
            }
            else
            {
                $image_check=        getimagesize($_FILES['image']['tmp_name']);
                
                if($image_check==false)
                {
                    echo 'Not a Valid Image';
                    }
                    else
                    {
                
                        $image                =file_get_contents ($_FILES['image']['tmp_name']    );
                        $image_name            =$_FILES['image']['name'];
                        
                        if ($image_query        =mysql_query ("insert into product_images values
                                                            (1,'$image_name',$image )"))
                                                            {
                                                                echo $current_id;
                                                                //echo 'Successfull';
                                                                }
                                                                else
                                                                {
                                                                    echo mysql_error();
                                                                    }
                    }
                    
                }
        /*-----------------
    IMAGE QUERY END
    ---------------------*/

<form action='insert_product.php' method='POST' enctype='multipart/form-data' ></br>
        File        : <input type='file' name= 'image' >
</form>

Error Message

 

 

Error Message 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 '' at line 1

 

 
Link to comment
https://forums.phpfreaks.com/topic/280274-error-in-uploading-image-in-database/
Share on other sites

You are also going to have to escape the data. See mysql_real_escape_string. You need to escape the filename as well.

 

Other things to consider:

 

1) The mysql_ extension has been depricated. New development should use the improved version: mysqli.

 

2) Storing the actual image in a database is generally not very beneficial.

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.