SHARE
TWEET

Untitled

a guest May 23rd, 2019 107 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.   if (isset($_POST['log'])) {
  3.     $login = $_POST['login'];
  4.     $passwd = $_POST['password'];
  5.     $servername = "localhost";
  6.     $username = "root";
  7.     $password = "";
  8.     $dbname = "security";
  9.     $conn = mysqli_connect($servername, $username, $password, $dbname);
  10.     if ($conn){
  11.       $sql = "SELECT id FROM users WHERE login ='".$login."'";
  12.       $result = mysqli_query($conn,$sql);
  13.       if (mysqli_num_rows($result)==0){
  14.         $sql = "INSERT INTO users (login,pass) VALUES ('".$login."','".$passwd."')";
  15.         $result = mysqli_query($conn,$sql);
  16.         echo $login.", Вы успешно зарегистрировались";
  17.       }
  18.       else
  19.       {
  20.         echo "Данный аккаунт зарегистрирован";
  21.       }
  22.     }
  23.     mysqli_close($conn);
  24.   }
  25.   function showForm() {
  26.     $string = "<form action = '".$_SERVER["SCRIPT_NAME"]."' method='post'>";
  27.     $string .= "<label>Login: </label>";
  28.     $string .= "<input type = 'text' name = 'login'>";
  29.     $string .= "<br />";
  30.     $string .= "<label>Password: </label>";
  31.     $string .= "<input type = 'password' name = 'password'>";
  32.     $string .= "<br /><br />";
  33.     $string .= "<input type = 'submit' name = 'log' value = 'Зарегистрироваться'>";
  34.     $string .= "</form>";
  35.     return $string;
  36.   }
  37. ?>
  38. <!DOCTYPE html>
  39. <html>
  40.   <head>
  41.   <meta charset="utf-8">
  42.     <title> Регистрация </title>
  43.    </head>
  44.     <body style="background-color:#F8F9FA">
  45.     <div class="container" style="width:94%; background:#D3D3D3; padding: 3%;";>
  46.     <div class="row">
  47.         <h1>Регистрация</h1>
  48.         <?php
  49.           $login = $_COOKIE['login'];
  50.           if ($login != "") echo "Hello, $login";
  51.           else echo showForm();
  52.         ?>
  53.     </div>
  54.     </div>
  55. </html>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top