Php Mysql Insert Into Database
Morning! I'm trying to make a login page where our employees can add products to our invoices. I've created a test page for you so you can follow easily and maybe see the idea of t
Solution 1:
You can generate the form with different names, for example:
<scripttype="text/javascript">
var i = 1;
function myFunction()
{
var table = document.getElementById("products");
var row = table.insertRow(-1);
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
var cell3 = row.insertCell(2);
var cell4 = row.insertCell(3);
cell1.innerHTML = '<td>Description <inputtype="text"name="description'+i+'"value=""></td>';
cell2.innerHTML = '<td>Qty <inputtype="text"name="qty'+i+'"value=""></td>';
cell3.innerHTML = '<td>Price <inputtype="text"name="price'+i+'"value=""></td>';
cell4.innerHTML = '<td><inputtype="button"onclick="removeRow(this)"value="Remove"></td>';
i++;
}
removeRow = function(el) {
$(el).parents("tr").remove()
}
</script>
And then in php you can just iterate through all names:
$i=1; $values = '';
while(isset($_POST['description'.$i])) {
$i++;
$values .= "($_POST[description$i],$_POST[qty$i],$_POST[price$i])"; // add escaping
}
mysql_query("insert into table_name (column1,column2,column3,...)
VALUES $values");
Post a Comment for "Php Mysql Insert Into Database"