Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. <?php
  2.  
  3. $db = new PDO('mysql:host=localhost;dbname=bh09uc;
  4. charset=utf8','root', '');
  5. try {
  6.  
  7. $sql = "SELECT * FROM Devices WHERE deviceid=:deviceid";
  8. //prepare statement
  9. $stmt = $db->prepare($sql);
  10. //get value from querystring and bind
  11. $id = filter_input(INPUT_GET, 'id');
  12. $stmt->bindValue(':deviceid', $id, PDO::PARAM_INT);
  13. //execute
  14. $stmt->execute();
  15. //create array of records
  16. $r = $stmt->fetch();
  17. $db = null;
  18. //check contents of array
  19. if (!$r){
  20. echo "No Device found";
  21. }
  22. } catch (PDOException $e) {
  23. //for development
  24. print "We had an error: " . $e->getMessage() . "<br/>";
  25. die();
  26. }
  27. ?>
  28.  
  29. ?>
  30.  
  31.  
  32. <?php } else {
  33.  
  34. try {
  35.  
  36. $db = new PDO('mysql:host=localhost;dbname=bh09uc; charset=utf8','root', '');
  37.  
  38. $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)";
  39. //named paramaters
  40. $stmt = $db->prepare($sql);
  41.  
  42. $fname = filter_input(INPUT_POST, 'fname');
  43. $stmt->bindValue(':fname', $fname, PDO::PARAM_STR);
  44.  
  45. $sname = filter_input(INPUT_POST, 'sname');
  46. $stmt->bindValue(':sname', $sname, PDO::PARAM_STR);
  47.  
  48. $address = filter_input(INPUT_POST, 'address');
  49. $stmt->bindValue(':address', $address, PDO::PARAM_STR);
  50.  
  51. $postcode = filter_input(INPUT_POST, 'postcode');
  52. $stmt->bindValue(':postcode', $postcode, PDO::PARAM_STR);
  53.  
  54. $town = filter_input(INPUT_POST, 'town');
  55. $stmt->bindValue(':town', $town, PDO::PARAM_STR);
  56.  
  57. $phone = filter_input(INPUT_POST, 'phone');
  58. $stmt->bindValue(':phone', $phone, PDO::PARAM_STR);
  59.  
  60. $email = filter_input(INPUT_POST, 'email');
  61. $stmt->bindValue(':email', $email, PDO::PARAM_STR);
  62.  
  63. $stmt->execute();
  64.  
  65. $sql2 = "SELECT customerid from customer where customer_email = :email";
  66.  
  67. $stmt2 = $db->prepare($sql2);
  68. $stmt2->bindValue(':email', $email, PDO::PARAM_STR);
  69.  
  70. $stmt2 -> execute();
  71. $customerid = $stmt2->fetch();
  72. echo $customerid['customerid']; // test to see cus id value
  73.  
  74. $id = filter_input(INPUT_GET, 'id');
  75. echo $id; //test to see id value
  76.  
  77.  
  78. $sql3 = 'INSERT INTO `orders` (`deviceid`, `customerid`) VALUES ("' . $id . '", "' . $customerid['customerid'] . '")';
  79. $stmt3= $db->prepare($sql3);
  80. $stmt3->execute();
  81.  
  82.  
  83. $db = null;
  84. print "Reservation added.";
  85.  
  86. } catch (PDOException $e) {
  87. //for development
  88. print "We had an error: " . $e->getMessage() . "<br/>";
  89. die();
  90. }
  91. }
  92. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement