I'll rephrase my question.
My problem is not storing only images.. but storing multiple images alongside with text, description, etc.. I researched all over stack overflow finding for the answer but most of what I found was answers related to storing images only. I would like to find how can I insert multiple data(name, image, description) at the same time.
The only part I am having difficulty is the multiple image part.
Also, my form is dynamically generated using jquery.
my db structure would be like
id | name | image | description | price
This is my HTML:
<td><input type="text" class="form-control" name="item[]" placeholder="Name of Item" /></td>
<td><input type="text" class="form-control" name="desc[]" placeholder="Description" /></td>
<td><input type="text" class="form-control" name="price[]" placeholder="Price" /></td>
<td><input type="text" class="form-control" name="brand[]" placeholder="Brand" /></td>
<td><input type="file" name="images" class="form-control" /></td>
<input type="submit" id="save-product" class="btn btn-success" name="submit" value="Submit">
This is my PHP:
if(isset($_POST['submit']) ){
$name = $_FILES['images']['name'];
$type = $_FILES['images']['type'];
$size = $_FILES['images']['size'];
$temp = $_FILES['images']['tmp_name'];
$error = $_FILES['images']['error'];
$allowed = array(
"image/jpeg",
"image/jpg",
"image/png");
$con = mysqli_connect("localhost","root", "", "db_elective");
if(in_array($type, $allowed) && $size < 2000000 && !empty($_POST['item'])){
$ext = end(explode(".", $name));
$newFilename = sha1(date("Y-m-d h:i:s")) . "." . $ext;
if(move_uploaded_file($temp, "../uploaded" . $newFilename)){
$item = $_POST['item'];
$desc = $_POST['desc'];
$price = $_POST['price'];
$brand = $_POST['brand'];
$image = $newFilename;
for($x = 0; $x < count($item); $x++){
$vItem = $item[$x];
$vdesc = $desc[$x];
$vbrand = $brand[$x];
$vImg = $image[$x];
$vprice = $price[$x];
mysqli_query($con, "INSERT INTO tb_items (product_name, product_desc, product_img, product_brand, price)
VALUES('$vItem','$vdesc', '$vImg', '$vbrand', '$vprice')");
}
}
}else{
echo "Wrong";
}
}