Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I insert multiple products when quantity is unknown?
    primarykey
    data
    text
    <p>I'm trying to build an inventory system to keep track of some products in my company. It isn't an online store or anything, just a way for me to keep track of what products are in shipping, in an electrician's truck stock, or in the office. </p> <p>I've already built pages to show current inventory levels of what's in limbo (shipping to a tech or the office), what techs have, and what is here in the office. I can also see what stock each tech has also. Now I just need a way to assign products to one of these locations when they are drop shipped by our supplier. </p> <p>The Insert Inventory page has a form that displays fields for every item we keep track of, and a quantity box next to it. It also has a select box for choosing what to assign the inventory to and where it is intended to go next. (For example: Shipping -> Tech)</p> <blockquote> <p><strong>So, it might look like this:</strong></p> <hr> <p><strong>Choose Location Type</strong> Select List</p> <p><strong>Choose Going To</strong> Select List</p> <p>12/2 Indoor Wire (Read Only)............Quantity Field</p> <p>10/2 Outdoor Cable (Read Only)..............Quantity Field</p> <p>Submit Button</p> <hr> </blockquote> <p>There is actually going to be about 60 products on this page. Ideally, if they put 10 in the 12/2 wire field, it'll insert into the database 10 records that have:</p> <blockquote> <p>id(<em>AI</em>), product_id, location_type_id, location_going_id, date</p> </blockquote> <p>And if I put 3 on 10/2 quantity then it will insert 3 records of that also.</p> <p>Here is the code for my form. Right now there's not much else.</p> <pre><code> &lt;form action="insert2.php" id="form1" name="form1" method="POST"&gt; &lt;table width="500" border="0"&gt; &lt;tr&gt; &lt;td&gt;&lt;input name="product_name[]" type="text" value="10/2 Outdoor Cable" readonly="readonly"&gt;&lt;/td&gt; &lt;td&gt;&lt;input name="qty[]" type="text" size="5"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;input name="product_name[]" type="text" value="12/2 Indoor Wire" readonly id="product_name[]"&gt;&lt;/td&gt; &lt;td&gt;&lt;input name="qty[]" type="text" size="5" id="qty[]"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;p&gt; &lt;input type="submit" name="submit" id="submit" value="Submit"&gt; &lt;/p&gt; &lt;/form&gt; </code></pre> <p>And then I have it going to the second page to insert it into the database:</p> <pre><code>&lt;?php for($i = 0; $i &lt; count($_POST['product_name']); $i++) { $product = $_POST['product_name'][$i]; for ($j = 0; $j &lt; $_POST['qty'][$i]; $j++) { mysqli_query($con,"INSERT INTO inv_inventory (product_name) VALUES ('$product')"); } } ?&gt; </code></pre> <p>When I get to the second page, it shows: <em>string(16) "12/2 Indoor Wire"</em> and it inserted 1 of the 10/2 outdoor cable items. I put 3 for outdoor and 4 for indoor products.</p>
    singulars
    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