Can anyone here help me on how can I use PHP
to insert multiple rows into a database with a single submit? I have tried doing it, but it only inserts one row.
Here is my code:
<?php
if(isset($_POST['insertData']))
{
$pred1 =$_POST['pre'];
$np1 =$_POST['nap'];
$sd101 =$_POST['tdisease'];
$pr1 =$_POST['pric1'];
$ivd =$_POST['invd'];
$id =$_POST['user'];
$pred1 =$_POST['pre1'];
$np1 =$_POST['nap1'];
$sd101 =$_POST['tdisease1'];
$pr1 =$_POST['pric1'];
$pred2 =$_POST['pre2'];
$np2 =$_POST['nap2'];
$sd102 =$_POST['tdisease2'];
$pr2 =$_POST['pric2'];
$insert_user="INSERT INTO invoices(id, icd10, nappi_code, prescription, price, invoice_date, pid) VALUES ('','$sd10', '$np' ,'$pred','$pr','$ivd','$id');";
$insert_user .="INSERT INTO invoices(id, icd10, nappi_code, prescription, price, invoice_date, pid) VALUES ('','$sd101', '$np1' ,'$pred1','$pr1','$ivd','$id');";
$insert_user .="INSERT INTO invoices(id, icd10, nappi_code, prescription, price, invoice_date, pid) VALUES ('','$sd102', '$np2' ,'$pred2','$pr2','$ivd','$id')";
if(mysqli_query($con,$insert_user))
{
echo"<script>alert(' Invoice Details successfuly added to database')</script>";
echo '<meta content="1;generate-invoive-results-date-report.php?id='.$id.'" http-equiv="refresh" />';// redirects user view page after 3
}else{
echo"<script>alert('Unknown error occured')</script>";
}
}
?>