<?php
if(isset($_POST['hour'])&&isset($_POST['day'])){
//the path to store the uploaded image.
$target = "images/".basename($_FILES['image']['name']);
$db = mysqli_connect("localhost","root","","a_database");
$image = $_FILES['image']['name'];
$carmodel = $_POST['carmodel'];
$cartype = $_POST['cartype'];
$hour = $_POST['hour'];
$day = $_POST['day'];
$query = "INSERT INTO `cardetails` (`image`, `carmodel`, `cartype`, `hour`, `day`) VALUES ('".$image."', '".$carmodel."', '".$cartype."', '".$hour."', '".$day."')";
mysqli_query($db,$query);//stores the data
//move uploaded image into the folder.
if(move_uploaded_file($_FILES['image']['tmp_name'],$target)){
header('Location:upload_success.php');
}else{
header('Location:upload_fail.php');
}
}else{
echo ' ';
}
?>
<div class="col-lg-offset-4">
<form method="POST" action="upload.php" enctype="multipart/form-data">
<input type="hidden" name="size" value="1000000">
<div class="form-group row">
<input type="file" name="image">
</div>
<div class="form-group col-lg-4 row">
<label> Car Model </label>
<select name="carmodel" class="form-control" >
<option value="Myvi">Myvi</option>
<option value="Vios">Vios</option>
<option value="Lambo">Lambo</option>
</select>
</div>
<div class="form-group row col-lg-offset-4">
<label> Car Type </label>
<input type="radio" name="cartype" value="Auto">Auto
<input type="radio" name="cartype" value="Manual"> Manual
</div>
<div class="form-group">
<input type="text" name="hour" placeholder="$/hour">
</div>
<div class="form-group">
<input type="text" name="day" placeholder="$/day">
</div>
<div class="form-group">
<button type="submit">Upload</button>
</div>
</form>
</div>
I've successfully insert the data into database with the image name but the image doesn't seems to upload into my images file, what could be wrong? Based on the code above, upload_fail.php is called. If isset with $_POST['image'], nothing happens.