Advertisement
Guest User

Untitled

a guest
Sep 11th, 2016
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.89 KB | None | 0 0
  1. <?php
  2. class User{
  3.     private $login;
  4.     private $email;
  5.     private $password;
  6.  
  7.     function __construct(){
  8.     }
  9.     function __construct2($login, $email, $password){
  10.         $this->login = $login;
  11.         $this->email = $email;
  12.         $this->password = $password;
  13.     }
  14.    
  15.     public function getLogin()
  16.     {
  17.         return $this->login;
  18.     }
  19.     public function setLogin($login)
  20.     {
  21.         $this->login = $login;
  22.     }
  23.     public function getEmail()
  24.     {
  25.         return $this->email;
  26.     }
  27.  
  28.     public function setEmail($email)
  29.     {
  30.         $this->email = $email;
  31.     }
  32.  
  33.     public function getPassword()
  34.     {
  35.         return $this->password;
  36.     }
  37.  
  38.     public function setPassword($password)
  39.     {
  40.         $this->password = $password;
  41.     }
  42.  
  43. }
  44.  
  45. <?php
  46. require_once ("User.php");
  47. $login = "root";
  48. $pass = "root";
  49. $host = "mylocalhost";
  50. $dbname = "user";
  51. $db = new PDO('mysql:host=localhost; dbname=user', $login);
  52. $user = new User();
  53. if($_SERVER['REQUEST_METHOD']=='POST'){
  54.     $user->setLogin($_POST['login']);
  55.     $user->setEmail($_POST['email']);
  56.     $user->setPassword($_POST['password']);
  57.  
  58.     print_r($user->getLogin());
  59.  
  60.     $sql = "INSERT INTO users(login, email, password)
  61.       VALUES ('$user->getLogin()', '$user->getEmail()', '$user->getPassword()')";
  62. $db->query($sql);
  63.   }
  64.  
  65. <!DOCTYPE html>
  66. <html lang="en">
  67. <head>
  68.     <meta charset="UTF-8">
  69.     <title>Title</title>
  70. </head>
  71. <body>
  72.     <form action="../php/addUser.php" method="post">
  73.         <lable>input you login</lable>
  74.         <input type="text" name="login" id="login" >
  75.         <lable>input you email</lable>
  76.         <input type="text" name="email" id="email" >
  77.         <lable>input you password</lable>
  78.         <input type="password" name="password" id="password" >
  79.         <button type="submit" name="btn">регистрация</button>
  80.  
  81.     </form>
  82. </body>
  83. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement