How do I use foreach loop on a dynamic table rows input fields?

Hello Below is my HTML and Jquery for a form:
https://codepen.io/Prezzy876/pen/rradRW

Here is the PHP im working on:

[php]<?php

if( isset($_POST[‘submit’]) )
{

if(isset($_POST[‘selectservice’])){

 $service = $_POST['selectservice'];
 $service_id = $db->escape( $_POST['service_id']);
 $estimate_id = $db->escape( $_POST['estimate_id']);
 $quantity = $db->escape( $_POST['quantity']);
 $discount_percent= $db->escape(   
 $_POST['discount_percent']);
 $client_id = $db->escape( $_POST['client_id']);
 $event_date = $db->escape( $_POST['event_date']);
 $project_name = $db->escape( $_POST['project_name']);
 $tdiscount = $db->escape( $_POST['tdiscount']);
 $ttax = $db->escape( $_POST['ttax']);

foreach($service as $s){
$db->query("INSERT INTO services_estimate   
(service_id,estimate_id,quantity,discount_percent)  
VALUES 
($service_id,$estimate_id ,$quantity ,$discount_percent)");

$db->query("INSERT INTO estimates 
(client_id,event_date,project_name,tdiscount,ttax) 
VALUES 
($client_id,$event_date ,$project_name ,$tdiscount, $ttax)");

}

}

}

?>[/php]
Here are my Mysql Database tables:

Table name: service_estimate
Columns: id, service_id, estimate_id, quantity, discount_percent

Table name: estimates
Columns: id, client_id, event_date, project_name, tdiscount, ttax

I am using ezSQL, I need help with the php to insert each row independently to the database tables listed above.any ideas?

Don’t know why you are using ezSQL, but it says that it is a wrapper for PDO.

Use prepared statements and just loop through. Though, you will need different values for it to make sense.

ezSQL is designed to be sued with several querying languages: https://github.com/ezSQL/ezSQL . It provides convenience and an added layer of security.

I someone could give me example code to point me in the right direction i would appreciate that very much.

Using prepared statements, ezSQL is actually an additional layer of complexity that slows an system down by additional overhead. PDO supports most databases, and outside of Linq, I know of no other query languages.

Pseudo code:

[php]Your prepared query

Start loop
Get New values for insert
Execute insert statement
End loop

[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service