1

i am building a script using php to upload images in database but i am stuck due to the error under: when i open my page in browser following message shows to me:

Notice: Undefined index: image in C:\xampp\htdocs\12\index.php on line 10 please select a file

under is my script in initial form :

<html>
<body>
<form action="index.php" method="post" enctype="multipart/form-data">
File:<input type="file" name="image" /><input type="submit" value="upload" />
</form>
<?php
mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db("databaseimage") or die(mysql_error());
//files properties
echo $file = $_FILES["image"]["tmp_name"];
if(!isset($file))
echo'please select a file';
else{
    $image = $_FILES['image']['tmp_name'];
    }
?>
</body>
</html>
1

1 Answer 1

2

Check, if there is an upload first (and therefore, $_FILES["image"] is existing at all):

if (isset($_FILES["image"]))
{
    $file = $_FILES["image"]["tmp_name"];
    if (!isset($file)) {
        echo 'please select a file';
    } else {
        $image = $_FILES['image']['tmp_name'];
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.