Terminaxx Posted November 4, 2017 Share Posted November 4, 2017 Hey guys, first i want to apologize for my english and hope you still understand the meaning of it. I list items that you can buy and also choose the number, how many items you want to buy. Code: foreach ($furnis as $f) { echo "<h3>$f->name</h3>"; echo "<h5>".number_format($f->price, 0, ",", ".")." Taler</h5>"; echo "$f->quantity x"; if($money >= $f->price) { echo "<input name='quantity' type='number' min='1' max='$f->quantity'>"; echo "<button type='submit' name='buy' value='$f->id'>Buy</button>"; }else { echo "<button>Not enough money</button>"; } } To get the aricle, which is clicked is easily done with getting the ID: $id = input($_POST['buy']); Now my question is, how to get the quantity (inputfield) right? When I try the same: $quantity = input($_POST['quantity']); I do not get the quantity. Of course I get it, if only one article is displayed, but there are many more. So instead of getting the quantity of the article the person clicked on, i get a random quantity from an other article. How can I do it right?Thanks for any help Quote Link to comment Share on other sites More sharing options...
Solution Barand Posted November 4, 2017 Solution Share Posted November 4, 2017 Create an array for the quantity inputs using the id as the key. <input name="quantity[$f->id]" type="number" >You can then access individual input $quantity = $_POST['quantity'][$id] Quote Link to comment Share on other sites More sharing options...
Terminaxx Posted November 4, 2017 Author Share Posted November 4, 2017 Thank you very much! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.