Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. <?php
  2. //insert.php
  3. //This page handles the inserting into the database of the new contact
  4.  
  5. require_once('db.inc.php');
  6.  
  7. $sql = "INSERT INTO mad9023_contacts (contact_first,
  8. contact_email) VALUES (:first, :last, :email)";
  9.  
  10. $query = $pdo->prepare($sql);
  11. $values = [
  12. ':first' => $_SERVER['HTTP_CONTACT_FIRST'],
  13. ':last' => $_SERVER['HTTP_CONTACT_LAST'],
  14. ':email' => $_SERVER['HTTP_CONTACT_EMAIL']
  15. ];
  16.  
  17. $stmt= $query->execute($values);
  18.  
  19. $result = $pdo->query("SELECT * FROM `mad9023_contacts` WHERE contact_id= LAST_INSERT_ID();");
  20.  
  21. $errorInfo = $pdo->errorInfo();
  22. if (isset($errorInfo[2])){
  23. echo $errorInfo[2];
  24. exit;
  25. }
  26.  
  27. //use one of these based on the parameters
  28. if (isset($_GET['type']) && $_GET['type'] == 'json'){
  29. header("Content-Type: application/json");
  30. echo json_encode(["success" => (bool) $result,"affected" => (int) $reult]);
  31. }
  32. header("Content-Type: text/xml");
  33. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement