Advertisement
Guest User

Untitled

a guest
Apr 11th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. <?php
  2. var_dump($_POST);
  3. function baseConnect(){
  4. $host = "localhost";
  5. $user = "root";
  6. $password = "Aphroditesçç";
  7. $dbname ="checkpoint1";
  8. try{
  9. $connexion = new PDO("mysql:host=$host; dbname=$dbname", $user, $password);
  10. $connexion->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
  11. $connexion->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
  12. return $connexion;
  13. }
  14. catch(PDOException $e){
  15. die('Echec: ' .$e->getMessage());
  16. }
  17. }
  18. $dbh = baseConnect();
  19. if ($_POST['civility'] == "Mr")
  20. $civility = 1;
  21. else
  22. $civility = 2;
  23. $req = "insert into contact (civility_id, lastname, firstname) values (".$civility.",'".$_POST['lastname']."','".$_POST['firstname']."');";
  24. echo $req;
  25. $reponse = $dbh->query($req);
  26.  
  27. $errors = array();
  28.  
  29. if (empty($_POST["firstname"])) {
  30. $errors["firstname1"] = "Your firstname cannot be empty";
  31. }
  32.  
  33.  
  34. if (empty($_POST["lastname"])) {
  35. $errors["lastname1"] = "Your lastname cannot be empty";
  36. }
  37.  
  38. if (count($errors) == 0) {
  39. header("Location: success.php");
  40. exit();
  41. }
  42.  
  43. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement