I'm trying to upload multiple images from a textbox to MYSQL database using PHP. But somehow it only inserts the last item from the array in the database.
I tried uploading using one image, and that worked.
What am I doing wrong?
form.php:
<form action="addpicture.php?id=<?php echo $prodID; ?>" method="POST" enctype="multipart/form-data">
<input type="file" name="image[]" multiple/>
<input type="submit" value="upload" name="image" class="btn btn-primary" />
</form>
Addpicture.php:
<?php
session_start();
include '../includes/config.php';
$prodID = $_GET['id'];
foreach(array_keys($_FILES['image']['error']) as $key){
$temp_name = $_FILES['image']['tmp_name'][$key];
$t_name = file_get_contents($temp_name);
$t_name = mysql_real_escape_string($t_name);
$insert = mysql_query("INSERT INTO tblpictures(prodID, foto) VALUES ('$prodID','$t_name')") or die(mysql_error());
header('location: form.php?prodID=' . $prodID);
exit();
}
?>
EDIT: SOLVED HTML 5 multi file upload with PHP
addslashes()is to SQL injection prevention as using a roll of toilet paper is to soaking up an ocean. Do NOT use it. You may think you're doing the right thing, but it's NOT a defense against sql injection in any real way.