I am trying to upload 4 images into my file directory and also I would like to save reference to them in the database. but with my current code below, what it does is that, it inserts another row in the database instead of putting image 1 into img1 and so on.
I have given up. I don't know what is it that I am doing wrong here.
<?php
if(isset($_POST['go']))
{
if(isset($_FILES['file_array']))
{
$name_array = $_FILES['file_array']['name'];
$tmp_name_array = $_FILES['file_array']['tmp_name'];
$type_array = $_FILES['file_array']['type'];
$size_array = $_FILES['file_array']['size'];
$error_array = $_FILES['file_array']['error'];
$currently_item = "";
for($i = 0; $i < count($tmp_name_array); $i++)
{
if(move_uploaded_file($tmp_name_array[$i],'users_posted_data/'.$name_array[$i]))
{
$currently_item = current($_FILES['file_array']['name']);
$sql = $conn->query("INSERT INTO posts(img1, img2, img3) Values('{$currently_item}')");
echo $name_array[$i] . "uploaded successfully" . '<br>';
}
else
{
}
}
}
}
?>
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="file_array[]"><br><br>
<input type="file" name="file_array[]"><br><br>
<input type="file" name="file_array[]"><br><br>
<input type="file" name="file_array[]"><br><br>
<input type="submit" name="go" value="Publish">
</form>