Advertisement
Guest User

Untitled

a guest
Oct 10th, 2017
410
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.91 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4.  
  5. function dbconnect($host, $user, $password, $db)
  6. {
  7.     $host = "localhost";
  8.     $user = "web";
  9.     $password = "web";
  10.     $db = "web";
  11.     global $link;
  12.     if(!($link= new mysqli($host, $user, $password, $db)))
  13.     {
  14.         echo 'Mysql error: ' .$link->connect_error;
  15.         exit();
  16.     }
  17.    
  18.     print_r($link->host_info);
  19. }
  20.  
  21. function user_check($login, $password)
  22. {
  23.     $login = $_POST['email'];
  24.     $password = $_POST['password'];
  25.     $login_check_query = "SELECT * FROM users WHERE email=?";
  26.     $password_check_query = "SELECT * FROM users WHERE password=?";
  27.     $stmt = $link->prepare($login_check_query);
  28.     $stmt->bind_param('s',$login);
  29.     $stmt->execute();
  30.     if(($stmt->affected_rows) > 0)
  31.     {
  32.         $stmt->close();
  33.         $stmt = $link->prepare($password_check_query);
  34.         $stmt->bind_param('s',$password);
  35.         $stmt->execute();
  36.         if(($stmt->affected_rows) > 0)
  37.         {
  38.             $stmt->close();
  39.             return true;
  40.             echo 'true';
  41.         }
  42.         else
  43.         {
  44.             $stmt->close();
  45.             return false;
  46.             echo 'false';
  47.         }
  48.     }
  49.  
  50. }
  51.  
  52. function registration($login, $password)
  53. {
  54.     $login = $_POST['email'];
  55.     $password = $_POST['password'];
  56.     $user_insert_query = "INSERT INTO users (password, email) VALUES(?,?)";
  57.     if(user_check($login,$password))
  58.     {
  59.         $stmt = $link->prepare($user_insert_query);
  60.         $stmt->bind_param('ss',$password,$login);
  61.         $stmt->execute();
  62.         $stmt->close();
  63.     }
  64.     else
  65.     {
  66.         echo 'Username busy';
  67.     }
  68.  
  69. }
  70.  
  71.  dbconnect();
  72.  
  73.  if(isset($_POST['email']) && isset($_POST['password']))
  74.  {
  75.     $login = $_POST['email'];
  76.     $password = $_POST['password'];
  77.     user_check($login, $password);
  78.  }
  79. ?>
  80.  
  81. <!DOCTYPE html>
  82. <html>
  83. <head>
  84. <title>Ololo</title>
  85. <meta charset="utf-8" />
  86. </head>
  87. <body>
  88.     <form action="index.php" method="POST">
  89.                 Email: <input type="text" name="email" /><br />
  90.                 Password: <input type="password" name="password" /><br />
  91.                 <input type="submit" value="GO"/>
  92.         </form>
  93.  
  94.  
  95. </body>
  96. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement