Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $db = new PDO('mysql:host=localhost;dbname=bh09uc;
- charset=utf8','root', '');
- try {
- $sql = "SELECT * FROM Devices WHERE deviceid=:deviceid";
- //prepare statement
- $stmt = $db->prepare($sql);
- //get value from querystring and bind
- $id = filter_input(INPUT_GET, 'id');
- $stmt->bindValue(':deviceid', $id, PDO::PARAM_INT);
- //execute
- $stmt->execute();
- //create array of records
- $r = $stmt->fetch();
- $db = null;
- //check contents of array
- if (!$r){
- echo "No Device found";
- }
- } catch (PDOException $e) {
- //for development
- print "We had an error: " . $e->getMessage() . "<br/>";
- die();
- }
- ?>
- ?>
- <?php } else {
- try {
- $db = new PDO('mysql:host=localhost;dbname=bh09uc; charset=utf8','root', '');
- $sql = "INSERT INTO customer (customer_first, customer_sur, customer_add, customer_postcode, customer_town, customer_phone, customer_email) VALUES (:fname, :sname, :address, :postcode, :town, :phone, :email)";
- //named paramaters
- $stmt = $db->prepare($sql);
- $fname = filter_input(INPUT_POST, 'fname');
- $stmt->bindValue(':fname', $fname, PDO::PARAM_STR);
- $sname = filter_input(INPUT_POST, 'sname');
- $stmt->bindValue(':sname', $sname, PDO::PARAM_STR);
- $address = filter_input(INPUT_POST, 'address');
- $stmt->bindValue(':address', $address, PDO::PARAM_STR);
- $postcode = filter_input(INPUT_POST, 'postcode');
- $stmt->bindValue(':postcode', $postcode, PDO::PARAM_STR);
- $town = filter_input(INPUT_POST, 'town');
- $stmt->bindValue(':town', $town, PDO::PARAM_STR);
- $phone = filter_input(INPUT_POST, 'phone');
- $stmt->bindValue(':phone', $phone, PDO::PARAM_STR);
- $email = filter_input(INPUT_POST, 'email');
- $stmt->bindValue(':email', $email, PDO::PARAM_STR);
- $stmt->execute();
- $sql2 = "SELECT customerid from customer where customer_email = :email";
- $stmt2 = $db->prepare($sql2);
- $stmt2->bindValue(':email', $email, PDO::PARAM_STR);
- $stmt2 -> execute();
- $customerid = $stmt2->fetch();
- echo $customerid['customerid']; // test to see cus id value
- $id = filter_input(INPUT_GET, 'id');
- echo $id; //test to see id value
- $sql3 = 'INSERT INTO `orders` (`deviceid`, `customerid`) VALUES ("' . $id . '", "' . $customerid['customerid'] . '")';
- $stmt3= $db->prepare($sql3);
- $stmt3->execute();
- $db = null;
- print "Reservation added.";
- } catch (PDOException $e) {
- //for development
- print "We had an error: " . $e->getMessage() . "<br/>";
- die();
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement