I have an HTML form to upload some values including two images, I have two folders named uploads and receipt, I have given the following query to insert if the user fills the form:
if(isset($_POST['submit'])) {
$name = $_FILES['image']['name'];
list($txt, $ext) = explode(".", $name);
$image_name = time().".".$ext;
$tmp = $_FILES['image']['tmp_name'];
$shame = $_FILES['image']['name'];
list($txt, $ext) = explode(".", $shame);
$receipt_name = time().".".$ext;
$tmp = $_FILES['image']['tmp_name'];
if(move_uploaded_file($tmp, 'uploads/'.$image_name) && move_uploaded_file($tmp, 'receipt/'.$receipt_name) ){
$sql = "INSERT INTO members (firstname, lastname, image, receipt) VALUES ('".$_POST['first_name']."','".$_POST['last_name']."' , '".$image_name."', '".$receipt_name."' )";
$mysqli->query($sql);
}
else {echo "Error";}
}
I am getting the following error:
Notice: Undefined offset: 1 in C:\xampp\htdocs\form\index.php on line 15
Notice: Undefined index: image in C:\xampp\htdocs\form\index.php on line 17 Error
Why is this query not adding the data to database, and not uploading the file?
Lets check if your code going in move_uploaded_file function or not and if yes then lets find out whats your query build.