Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- try
- {
- $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password, array(PDO::ATTR_PERSISTENT => true));
- }
- catch(PDOException $e)
- {
- echo $conn . "<br>" . $e->getMessage();
- exit();
- }
- try
- {
- // set the PDO error mode to exception
- $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- // start transaction
- $conn->beginTransaction();
- $conn->query("SET NAMES 'utf8'");
- $q="SELECT * FROM synagogue.customer_table WHERE first_name='$first_name' AND last_name='$last_name'";
- $query_res = $conn->query($q);
- $count= count($query_res->fetchAll());
- if($count > 0)
- {
- echo "מתפלל קיים";
- }
- else
- {
- $table_customer = "customer_table";
- $table_debts = "debts_balance";
- $data_customer = array
- (
- "first_name" => "$first_name",
- "last_name" => "$last_name",
- "address" => "$address",
- "tel" => "$tel",
- "mail" => "$mail"
- );
- $sql = "INSERT INTO `$table_customer` (`".implode('`,`',array_keys($data_customer))."`) VALUES ('".implode('\',\'',array_values($data_customer))."');";
- $conn->exec($sql);
- // read the last ID
- $last_id = $conn->lastInsertId();
- $date = date('Y-m-d');
- $sql = "INSERT INTO `synagogue`.`debts_balance` (customer_id, date, debt_balance) VALUES ('$last_id', '$date', 0)";
- $conn->exec($sql);
- $conn->commit();
- echo "ברוך הבא למתפלל החדש";
- }
- }
- catch(PDOException $e)
- {
- $conn->rollBack();
- echo $sql . "<br>" . $e->getMessage();
- }
- $conn = null;
- ?>
Add Comment
Please, Sign In to add comment