Ania2019

Untitled

May 11th, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. <?php
  2. ini_set('display_errors', 'on');
  3.  
  4. session_start();
  5. require_once 'database.php';
  6.  
  7. if (isset($_POST['email'])) {
  8. $emailQuery = $db->prepare('SELECT * FROM users WHERE email = :newemail');
  9. $emailQuery->bindValue(':newemail', $email, PDO::PARAM_STR);
  10. $emailQuery->execute();
  11. $email = $emailQuery->rowCount();
  12. print_r($email);
  13. }
  14.  
  15. // if email is correct syntax
  16.  
  17. if (isset($_POST['email'])) {
  18. $email = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL);
  19.  
  20. //if email is not correct syntax
  21. if (empty($email)) {
  22.  
  23. //nie powiodlo sie echo $_POST['email']. "<br/>" .$email;
  24. $_SESSION['given_email'] = $_POST['email'];
  25. header('Location: index.php');
  26.  
  27. } else {
  28.  
  29.  
  30. //poprawny adres echo $_POST['email']. "<br/>" .$email;
  31. // input into DB
  32.  
  33. $query = $db->prepare('INSERT INTO users VALUES (NULL, :email)');
  34. $query->bindValue(':email', $email, PDO::PARAM_STR);
  35. $query->execute();
  36. }
  37.  
  38. } else {
  39.  
  40.  
  41. header('Location: index.php');
  42. exit();
  43. }
  44.  
  45.  
  46. ?>
  47. <!DOCTYPE html>
  48. <html lang="pl">
  49. <head>
  50.  
  51. <meta charset="utf-8">
  52. <title>Zapisanie się do newslettera</title>
  53. <meta name="description" content="Używanie PDO - zapis do bazy MySQL">
  54. <meta name="keywords" content="php, kurs, PDO, połączenie, MySQL">
  55.  
  56. <meta http-equiv="X-Ua-Compatible" content="IE=edge">
  57.  
  58. <link rel="stylesheet" href="main.css">
  59. <link href="https://fonts.googleapis.com/css?family=Lobster|Open+Sans:400,700&amp;subset=latin-ext" rel="stylesheet">
  60. <!--[if lt IE 9]>
  61. <script src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.min.js"></script>
  62. <![endif]-->
  63.  
  64. </head>
  65.  
  66. <body>
  67.  
  68. <div class="container">
  69.  
  70. <header>
  71. <h1>Newsletter</h1>
  72. </header>
  73.  
  74. <main>
  75. <article>
  76. <p>Dziękujemy za zapisanie się na listę mailową naszego newslettera!</p>
  77. </article>
  78. </main>
  79.  
  80. </div>
  81.  
  82. </body>
  83. </html>
Advertisement
Add Comment
Please, Sign In to add comment