Advertisement
Guest User

Untitled

a guest
Feb 29th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. <?php
  2. $servername = "localhost";
  3. $username = "root";
  4. $password = "usbw";
  5. $dbname = "persons";
  6.  
  7. // CREATE A CONNECTION WITH THE DATABASE
  8. $conn = new mysqli($servername, $username, $password, $dbname);
  9. if ($conn->connect_error) {
  10. die("Connection failed: " . $conn->connect_error);
  11. }
  12.  
  13. // ADDRESS APPEND - PREPARE SQL STATEMENT AND BIND PARAMS
  14. $stmt = $conn->prepare("INSERT INTO address (address_street, address_housenumber,
  15. address_zipcode, address_city, address_state)
  16. VALUES (?, ?, ?, ?, ?)");
  17. $stmt->bind_param("sssss", $straat, $huisnummer, $postcode, $stad, $provincie);
  18.  
  19. $straat = htmlspecialchars($_POST[straat]);
  20. $huisnummer = htmlspecialchars($_POST[huisnummer]);
  21. $postcode = htmlspecialchars($_POST[postcode]);
  22. $stad = htmlspecialchars($_POST[stad]);
  23. $provincie = htmlspecialchars($_POST[provincie]);
  24.  
  25. // EXECUTE STATEMENT
  26. $result = $stmt->execute();
  27. if ($result === FALSE) {
  28. die("Error: " . $stmt->error);
  29. }
  30.  
  31. // CAPTURE LAST INSERTED address_id
  32. $last_id = $conn->insert_id;
  33.  
  34. // PERSON APPEND - PREPARE SQL STATEMENT AND BIND PARAMS
  35. $stmt = $conn->prepare("INSERT INTO person (person_firstname, person_lastname,
  36. person_email, person_phonenumber,
  37. person_cv, person_address)
  38. VALUES (?, ?, ?, ?, ?, ?)");
  39. $stmt->bind_param("sssssi", $firstname, $lastname, $email, $telephone, $cv, $last_id);
  40.  
  41. $firstname = htmlspecialchars($_POST[firstname]);
  42. $lastname = htmlspecialchars($_POST[lastname]);
  43. $email = htmlspecialchars($_POST[email]);
  44. $telephone = htmlspecialchars($_POST[telephone]);
  45. $cv = htmlspecialchars($_POST[cv]);
  46.  
  47. // EXECUTE STATEMENT
  48. $result = $stmt->execute();
  49. if ($result === TRUE) {
  50. $URL="http://localhost:8080/Website/bedankt.php";
  51. header ("Location: $URL");
  52. } else {
  53. echo "Error: " . $stmt->error;
  54. }
  55.  
  56. $stmt->close();
  57. $conn->close();
  58.  
  59. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement