<?php
$qry=mysql_query("INSERT INTO ingredients(item,quantity,unm)VALUES('$items','$quantitys','$unm')", $con);//edited
?>
<script>
$(document).ready(function(e){
//variables
var html = '<p/><div>item: <input type="text" name="item" id="childitem"/>quantity: <input type="text" name="quantity" id="childquantity"/><a href="#" id="remove"> X </a></div>';
var maxrows = 25;
var x = 1;
//add rows to the form
$("#add").click(function(e){
if(x <= maxrows){
$("#container").append(html);
x++;
}
});
//remove rows
$("#container").on('click','#remove',function(e){
$(this).parent('div').remove();
x--;
});
});
</script>
Asked
Active
Viewed 29 times
0

krlzlx
- 5,752
- 14
- 47
- 55

RiyAs MuhaMmed
- 17
- 7
-
Where do you set `$items`? – Barmar Feb 13 '17 at 08:07
-
All your inputs have the same `name="item"`. When you submit the form, PHP will only see the last one. You should use an array-style `name="item[]"`, then `$_POST['item']` will be an array of all the inputs. – Barmar Feb 13 '17 at 08:08
-
Also, IDs must be unique, you can't have `id="childitem"` on all of them. Use a class instead. – Barmar Feb 13 '17 at 08:09
-
In your PHP, you should have a loop to process all the inputs. – Barmar Feb 13 '17 at 08:09
-
could you please define loop – RiyAs MuhaMmed Feb 13 '17 at 08:42
-
`foreach ($_POST['item'] as $item)` – Barmar Feb 13 '17 at 08:45
-
1What kind of programmer doesn't know what a loop is? – Barmar Feb 13 '17 at 08:45
-
sorry, im new to prgramming. – RiyAs MuhaMmed Feb 13 '17 at 08:58
-
@RiyAsMuhaMmed it must be week 1 of your course then if you don't know about looping. Lastly, your SQL is vulnerable to SQL Injection attacks. Get into good habits _now_ and learn to use parameterised queries. You can find a tutorial anywhere. Otherwise an attacker could find a way to delete all your data. – ADyson Feb 13 '17 at 10:24
-
@Barmar could you please look in to this?http://stackoverflow.com/questions/42219786/form-didnt-working-with-mysql – RiyAs MuhaMmed Feb 14 '17 at 13:58