Note that there are some explanatory texts on larger screens.

plurals
  1. POStoring multiple images in mysql
    primarykey
    data
    text
    <p>I'll rephrase my question.</p> <p>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. </p> <p>The only part I am having difficulty is the multiple image part.</p> <p>Also, my form is dynamically generated using jquery.</p> <p>my db structure would be like</p> <h1>id | name | image | description | price</h1> <p>This is my HTML:</p> <pre><code>&lt;td&gt;&lt;input type="text" class="form-control" name="item[]" placeholder="Name of Item" /&gt;&lt;/td&gt; &lt;td&gt;&lt;input type="text" class="form-control" name="desc[]" placeholder="Description" /&gt;&lt;/td&gt; &lt;td&gt;&lt;input type="text" class="form-control" name="price[]" placeholder="Price" /&gt;&lt;/td&gt; &lt;td&gt;&lt;input type="text" class="form-control" name="brand[]" placeholder="Brand" /&gt;&lt;/td&gt; &lt;td&gt;&lt;input type="file" name="images" class="form-control" /&gt;&lt;/td&gt; &lt;input type="submit" id="save-product" class="btn btn-success" name="submit" value="Submit"&gt; </code></pre> <p>This is my PHP:</p> <pre><code>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) &amp;&amp; $size &lt; 2000000 &amp;&amp; !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 &lt; 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"; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload