error Please select an imageError: Duplicate entry '' for key 'img'

`

                   //file properties
$file = $_FILES['image']['tmp_name'];


if(!isset($file))
    echo "Please select an image";
else
{
    $image = addslashes(file_get_contents($_FILES['image']['tmp_name']));
    $image_name = addslashes($_FILES['image']['img']);
    $image_size = getimagesize($_FILES['image']['tmp_name']);


    if($image_size==FALSE)
        echo "That's not an image.";
    else
    {
        {
        if(!$insert =  msql_query("INSERT INTO shop (id, img, name, description, price, product_qty,  product_category,imagesize)  
                                             VALUES ('','$image_name', '','','','','','$image')"))
            echo "Problem uploading image.";
        else
        {
        $lastid = mysql_insert_id();
        echo "image uploaded.<p />Your image :<p /><img src=get.php?id=$lastid>";
        }   

    }   
}   
}

Recommended Answers

All 4 Replies

Have you set img field as a primary key?

yes i have problem in saving my plaod photo in the database instead of pic.1.png -- in my database its said images/products/.png ---------------im doing a shopping cart .admin panel please help for my thesis

heres my new code

  // Image Load 


//file properties
$file = $_FILES['image']['tmp_name'];

                        if(!isset($file))
                            echo "Please select an image";
                        else
                    {
                        $image = addslashes(file_get_contents($_FILES['image']['tmp_name']));
                        $image_name = addslashes($_FILES['image']['name']);
                        $image_size = getimagesize($_FILES['image']['tmp_name']);


                        if($image_size==FALSE)
                            echo "That's not an image.";
                        else
                    {
                        if(!$insert =  msql_query("INSERT INTO shop VALUES('$st_id','$image_name','$productname','$image' ,'$description','$price','$product_qty','$_REQUEST[product_category]' "))
                            echo "problem uploading image";
                        else 
                            {
        $lastid = mysql_insert_id();
        echo "image uploaded.<p />Your image :<p /><img src=get.php?id=$lastid>";
        }

                    }
                    }
                    }}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.