I have a php form that when working will insert into db, e-mail notification, and allow optional upload of document. The db & mail portion work, however the file upload does not. At one point I did get working a file upload on a separate page. Right now I have 'error_reporting(-1);' in php.ini, and in the Apache log file nothing is shown indicating where the fault lies. Am I trying to do too much in the same form? Is there a way to get more detailed error reporting to figure out what is going wrong?
<?php
include('connect.php');
if((isset($_POST['username']) && !empty($_POST['username']))
&& (isset($_POST['email']) && !empty($_POST['email']))
&& (isset($_POST['city']) && !empty($_POST['city']))
&& (isset($_POST['state']) && !empty($_POST['state']))
&& (isset($_POST['file1']) && !empty($_POST['file1']))
&& (isset($_POST['file2']) && !empty($_POST['file2']))){
//if((isset($_POST['username']) && (!empty($_POST['username']))) && (isset($_POST['email']) && !empty($_POST['email'])) && (isset($_POST['subject']) && !empty($_POST['subject']))){
print_r($_POST);
$username = $_POST['username'];
$email = $_POST['email'];
$city = $_POST['city'];
$state = $_POST['state'];
$name= $_FILES['file']['name'];
$tmp_name= $_FILES['file']['tmp_name'];
$submitbutton= $_POST['submit'];
$position= strpos($name, ".");
$fileextension= substr($name, $position + 1);
$fileextension= strtolower($fileextension);
$file1= $_POST['file1'];
$to = "someone@somewhere.com";
$headers = "From : " . $email;
if( mail($to, $username, $city, $headers)){
echo "<strong>E-Mail Sent successfully, we will get back to you soon.</strong>";
$query = "INSERT INTO `contact` (username, email, city, state, file1, file2) VALUES ('$username', '$email', '$city', '$state', '$zip', '$file1', '$file2')";
$result = mysqli_query($connection, $query);
if (isset($name)) {
$path= 'uploads/';
if (!empty($name)){
if (move_uploaded_file($tmp_name, $path.$name)) {
echo 'Uploaded!';
}
}
}
}
}
?>
<html><head></head><body>
<div class="container">
<form class="form-contact" method="POST" multipart/form-data>
<input type="name" name="username" id="inputusername" class="auto-style7" placeholder="Your Name" required><span class="auto-style6">
<input type="email" name="email" id="inputEmail" class="auto-style7" placeholder="Your E-Mail Address">
<input type="name" name="city" id="inputcity" class="auto-style7" placeholder="Your City">
<input type="name" name="state" id="inputstate" class="auto-style7" placeholder="Your State">
<p></p>
Select file1: <input type="file" name="file1">
Select file2: <input type="file" name="file2">
<br>
<button class="btn btn-lg btn-primary btn-block" type="submit">Send</button></form>
</div>
</body>
</html>