I'm using MySQL query to insert multiple records into table. In my url i get all records that i have entered but in database it only updates my last record. I am using here onclick function to add new table rows. Any help. Here is my code
if (isset($_GET['submit']))
{
require_once("shine_class.php");
$s = new shine;
$s->connection();
$date1 = date_default_timezone_set('Asia/Kolkata');
$date1= time() ;
$newdate1 = date("d-m-Y", $date1);
for ($i=0; $i < count($_GET['finished_product_name']); $i++ )
{
$product =$_GET['finished_product_name'];
$material = $_GET['material_name'];
$quantity = $_GET['product_quantity'];
// mysql_query("INSERT INTO material_used (product_name, material_name, product_quantity, date) VALUES ('$a', '$b', '$c','$newdate1')") or die(mysql_error());
$insert ="insert into material_used set `product_name` = '".$product."', `material_name` = '".$material."', `product_quantity` = '".$quantity."',`date` = '".$newdate1."' ";
$select = mysql_query($insert) or die(mysql_error());
}
}
You try to assign a value with same name.so your last value replace with the existing value.
for example :your URL look like,
so your
$_GET['finished_product_name']
has value ispqr
notabc
.If you can change the field name with include
[]
, then PHP will create an array containing all of the matching values:your URL example like,
your for loop is :
use following function to insert data in DB