Advertisement
molik

Zliczanie ile adresów email jest w bazie danych

Oct 31st, 2017
446
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.58 KB | None | 0 0
  1. <?php
  2.     if(!isset($_SESSION['userId'])){
  3.         //  Jeżeli użytkownik nie jest zalogowany - wyświetl formularz logowania:
  4.          if(!isset($_POST['sub_loginUser'])){
  5.             // Jeżeli formularz nie został wysłany wyświetl go:
  6.             include_once 'sites/form-userLogin.html.php';
  7.          } else {
  8.              // Jeżeli formularz został wysłąny
  9.             if(empty($_POST['userEmail']) OR empty($_POST['userPassword'])){
  10.                 $alert = new Alert();
  11.                 $alert->showAlert('warning', 'Uzupełnij <strong>wszystkie</strong> dane logowania.');
  12.                 include_once 'sites/form-userLogin.html.php';
  13.             } else {
  14.                 try {
  15.                     include_once 'connect.php';
  16.                     $s = $pdo->prepare('SELECT email, password FROM users WHERE email = :email AND password = :password');
  17.                     $s->bindValue(':email', $_POST['userEmail']);
  18.                     $s->bindValue(':password', SHA1($_POST['userPassword']));
  19.                     $s->execute();
  20.                 } catch (PDOException $e) {
  21.                     $alert = new Alert();
  22.                     $alert->showAlert('warning', 'Wystąpił błąd w trakcie pobierania danych logowania do sprawdzenia.');
  23.                 }
  24.  
  25.                 /*  
  26.                     ------------------------------------------------------------------------------------
  27.                     Funkcja oblicza ilość zwróconych wierszy, czyli defakto ile osób jest w bazie danych
  28.                     Źródło: http://php.net/manual/en/pdostatement.rowcount.php
  29.  
  30.                     $count = $s->rowCount();
  31.                     ------------------------------------------------------------------------------------
  32.                 */
  33.                 $count = $s->rowCount();
  34.  
  35.  
  36.                 echo '<p>Podliczone <strong>rowCount</strong>: '.$count.'</p>';
  37.                 if($count != 0){
  38.                     $alert = new Alert();
  39.                     $alert->showAlert('success', 'Istnieje taka osoba w Naszej bazie danych.');
  40.                 } else {
  41.                     $alert = new Alert();
  42.                     $alert->showAlert('danger', 'Taka osoba nie istnieje w Naszej bazei danych.');
  43.                 }
  44.  
  45.                 $alert = new Alert();
  46.                 $alert->showAlert('success', 'Poprawnie wypełniłeś formularz logowania.');
  47.  
  48.                 $s->closeCursor();
  49.                 $pdo = null;
  50.             }
  51.          }
  52.     } else {
  53.         //  Jeżeli użytkownik jest zalogowany sprawdź, czy formularz logowania został wysłany
  54.  
  55.     }
  56. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement