File Upload don't work
Posted: 18 Apr 2017, 09:09
Hello! i have a script that insert some details in MySql database but the file upload don't work.Have you any ideea why don't work ?
Code: Select all
if(isset($_POST['submit']))
{
// get values form input text and number
$id = trim($_GET['id']);
$subiect = $_POST['motiv'];
$mesaj = $_POST['coment'];
$contact = $_POST['perioada'];
$data = date('m/d/Y');
$target = "images/";
$fileName = $_FILES['Filename']['name'];
$fileTarget = $target.$fileName;
$tempFileName = $_FILES["Filename"]["tmp_name"];
$fileDescription = $_POST['Description'];
$result = move_uploaded_file($tempFileName,$fileTarget);
/*
* If file was successfully uploaded in the destination folder
*/
if($result) { echo "FIle uploaded";
}
// mysql query to insert data
$servername = "localhost";
$username = "";
$password = "";
$dbname = "";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO contact2 (location,subiect,mesaj,imagine,contact,data)
VALUES ('$id', '$subiect','$mesaj','$fileName','$contact','$data')";
if ($conn->query($sql) === TRUE) {
$last_id = $conn->insert_id;
echo "Your message was se";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
}
?>