I have a form which has two different type of inputs. one is type='file' and another is type='text'. Now I'm trying to send these inputs to my database by using formdata() in jquery but what ever I do I can't send both inputs.
<form class='form-group' id='first_banner_form' enctype='multipart/form-data'>
<label class='btn btn-warning btn-block textbutton'>
upload your image<input type='file' class='hidden'
name='banner_number_one' id='banner_number_one'/>
</label>
<br>
<input type='text' class='form-control' name='banner_number_one_addr' id='banner_number_one_addr'
placeholder='write your name' style='text-align:center'/>
<hr>
</form>
<br>
<hr>
<br>
<button class='btn btn-success btn-block textbutton' id='upload_a_banner'>Upload</button>
and this is my jquery code
$(document).on('click','#upload_a_banner',function(){
var banner_form = new FormData($('#first_banner_form')[0]);
$.ajax({
url:'phpScript/upload_new_banners.php',
method:'POST',
data:banner_form,
async: false,
cache: false,
contentType: false,
processData: false,
success:function(data)
{
if(data=='done')
{
alert('uploaded');
}elseif(data=='file is not set')
{ alert('database couldn\'t recieve all data');
}
else{
alert(data);
}
},error:function()
{
alert('error');
}
});
});
and this is php code
if(isset($_FILES['banner_number_one']) && isset($_FILES['banner_number_one_addr']))
{
# the image
$fr_banner_name = $_FILES['banner_number_one']['name'];
$fr_banner_temp = $_FILES['banner_number_one']['tmp_name'];
#the link
$fr_link = $_FILES['banner_number_one_addr']['name'];
}else{
echo 'file is not set';
exit;
}
when I just write
if(isset($_FILES['banner_number_one']))
everything works but when I write
if(isset($_FILES['banner_number_one']) && isset($_FILES['banner_number_one_addr']))
I recieve 'file is not set' message. what should I do?