Advertisement
Guest User

Untitled

a guest
Apr 21st, 2019
82
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.  
  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. if ($_POST){
  19.  
  20. $dbh = baseConnect();
  21. if ($_POST['civility'] == "Mr")
  22. $civility = 1;
  23. else
  24. $civility = 2;
  25. $req = "insert into contact (civility_id, lastname, firstname) values (".$civility.",'".$_POST['lastname']."','".$_POST['firstname']."');";
  26.  
  27.  
  28. $errors = array();
  29.  
  30. if (empty($_POST["firstname"])) {
  31. $errors["firstname1"] = "Your firstname cannot be empty";
  32. }
  33.  
  34.  
  35. if (empty($_POST["lastname"])) {
  36. $errors["lastname1"] = "Your lastname cannot be empty";
  37. }
  38.  
  39. if (count($errors) == 0) {
  40. $reponse = $dbh->query($req);
  41. header("Location: success.php");
  42. exit();
  43. }
  44.  
  45. }
  46. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement