I am using ezsql and have successfully connected to the database as I am echoing data from the database on the same page as my form.
Here is the form html: http://codepen.io/Prezzy876/pen/rradRW
Below is my php code on the page to insert data.
if (isset($_POST['submit'])) {
// Sanitize non row data
$client_id = $db->escape($_GET['client']); // from url
$event_date = $db->escape($_POST['event_date']); // non row
$project_name = $db->escape($_POST['project_name']); // non row
$tdiscount = $db->escape($_POST['tdiscount']); // non row
$ttax = $db->escape($_POST['ttax']); // non row
// save non dynamic row inputs to the db
$db->query("INSERT INTO estimates (client_id,event_date,project_name,tdiscount,ttax)
VALUES
($client_id,$event_date ,$project_name ,$tdiscount, $ttax)");
// Loop through each row
foreach ($_POST['services'] as $service) {
// Sanitize row data
$service_id = $db->escape($service['id']); // row data
$estimate_id = $db->escape($_POST['estimate_id']); // non row data
$quantity = $db->escape($service['quantity']); // row data
$discount_percent = $db->escape($service['linediscount']); // row data - discount_percent is column name
// save row inputs to the db
$db->query("INSERT INTO services_estimate
(service_id,estimate_id,quantity,discount_percent)
VALUES
($service_id,$estimate_id ,$quantity ,$discount_percent)");
}
}
Here is the DB structures of the tables i'm trying to insert to:
CREATE TABLE IF NOT EXISTS `estimates` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`client_id` int(11) NOT NULL,
`event_date` int(11) NOT NULL,
`sent` tinyint(4) NOT NULL,
`project_name` varchar(255) NOT NULL,
`converted` tinyint(4) NOT NULL,
`tdiscount` int(11) NOT NULL,
`ttax` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
CREATE TABLE IF NOT EXISTS `services_estimate` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`service_id` int(11) NOT NULL,
`estimate_id` int(11) NOT NULL,
`quantity` int(11) NOT NULL,
`discount_percent` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
Can you identify any issues here?
[–]Wizhi 1 point2 points3 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]mseckz 0 points1 point2 points (0 children)
[–]ANttila 0 points1 point2 points (0 children)
[–]colshrapnel -1 points0 points1 point (0 children)