I'm trying to write a script that allows people to either upload a file or add a link to the database. I don't want it to do both, but I can't seem to get my error messages right. Here's the code for my messages.
Code:
if (!$_POST['report_url'] && !$_FILES['uploaded_file']){
die('You did not complete all of the required fields, <a href="addreport.php">Return</a>');
}
if ($_POST['report_url'] == true && $_FILES['uploaded_file'] == true){
die('You can only upload a report OR post a link to a report, not both, <a href="addreport.php">Return</a>');
}
if (isset($_FILES['uploaded_file'])){
if(!$_FILES['uploaded_file']['error'] == 0);
die('there was a problem with your upload');
}
I think what's happening is that $_FILES is set regardless of whether or not I put anything into the corresponding input box, because if I don't put anything in either box it skips to error 3 and it I put something into only report_url it fires off error 2. Is this the problem and if so how do I fix it?
Code:
if (!$_POST['report_url'] && !$_FILES['uploaded_file']){
die('You did not complete all of the required fields, <a href="addreport.php">Return</a>');
}
if ($_POST['report_url'] == true && $_FILES['uploaded_file'] == true){
die('You can only upload a report OR post a link to a report, not both, <a href="addreport.php">Return</a>');
}
if (isset($_FILES['uploaded_file'])){
if(!$_FILES['uploaded_file']['error'] == 0);
die('there was a problem with your upload');
}
I think what's happening is that $_FILES is set regardless of whether or not I put anything into the corresponding input box, because if I don't put anything in either box it skips to error 3 and it I put something into only report_url it fires off error 2. Is this the problem and if so how do I fix it?