Forum Moderators: coopster
I am submitting a form with one image upload option. Now problem is that if a user submit form without choosing any image my script is displaying a blank page and not insert data in db. But when i select image with submition of formit is working fine.
I think problem is i have to check whether file is selected or not. I am using like this
if(isset($_POST['submit']))
{
if(isset($_POST['userfile']))
{
echo "image selected";
if (isset($_FILES['userfile']))
{
//code to uplaod image
}
}
else
{
echo "no image selected";
}
}
[/code]
when i use this it always falls in else condition that no image selected whether i choose image or not.
can any body help me what is problem inthis.
Vinic
if(isset($_POST['submit'])) {
if(isset($_POST['userfile'])) {
echo "image selected";
if (isset($_FILES['userfile'])) {
//code to uplaod image
}
} else {
echo "no image selected";
}
} if (isset($_FILES['userfile']) && trim($_FILES['userfile'])) {
//code to uplaod image
} else {
echo "no image selected";
}