I want to insert
values of data array in 3 tables. In one insert
everything works fine, but in multiple inserts no. Also, is there any way to cancel the procedure if 1/3 table insert fails?
My code:
if($_POST["action"] == 'Add')
{
$data = array(
':afm' => $_POST["afm"],
':fname' => $visitor->clean_input($_POST["fname"]),
':lname' => $visitor->clean_input($_POST["lname"]),
':city' => $visitor->clean_input($_POST["city"]),
':street' => $visitor->clean_input($_POST["street"]),
':company' => $_POST["company"],
':email' => $_POST["email"],
':phone' => $_POST["phone"],
':make' => $_POST["make"],
':model' => $_POST["model"],
':gen' => $_POST["gen"],
':engine' => $_POST["engine"],
':plate' => $_POST["plate"],
':vin' => $_POST["vin"]
);
$visitor->query = "
INSERT INTO Client
(afm, fname, lname, city, street, company, email)
VALUES (:afm, :fname, :lname, :city, :street, :company, :email)
";
$visitor->query = "
INSERT INTO Phone
(phone_type, phone, clientID)
VALUES ("main phone", :phone, :afm)
";
$visitor->query = "
INSERT INTO Vehicle
(plate, make, model, gen, engine, vin, clientID)
VALUES (:plate, :make, :model, :gen, :engine, :vin, :afm)
";
$visitor->execute($data);
echo '<div class="alert alert-success">success!</div>';
}