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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.