I am trying to add data into 2 tables using PHP
My PHP code: insert.php
<?php session_start(); $db['host'] = "dbhost"; $db['user'] = "user"; $db['pass'] = "pass"; $db['name'] = "dbname"; //making an array with the data recieved $data = array('f_name' => $_POST['txt_f_name'], 'l_name' => $_POST['txt_l_name'], 'VNum' => $_POST['txtVisaNo']); try { // preparing database handle $dbh $dbh = new PDO("mysql:host=".$db['host']."; dbname=".$db['name']."", $db['user'], $db['pass']); // set the PDO error mode to exception $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $insertall = "BEGIN; " . "INSERT INTO students (f_name, l_name) " . "VALUES (:f_name, :l_name); " . "INSERT INTO visa (students_id, VNum) " . "VALUES (:LAST_INSERT_ID(), :VNum); " . "$addStdInf->execute($data); " . "COMMIT;"; $addStdInf = $dbh->prepare($insertall); echo 'Success!'; } catch(PDOException $e){ echo $sql,'<br />', $e->getMessage(); } $dbh = null; ?> Notice is "Success!" but it inserted nothing into database, please guide me the ERROR.Thank you.
preparethe statement but neverexecutethe query. php.net/manual/en/pdostatement.execute.php