Advertisement
Guest User

Untitled

a guest
Jun 30th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.37 KB | None | 0 0
  1. <?php
  2. class work_DB {
  3.     public $host = 'localhost';
  4.     public $username = 'root';
  5.     public $password = '';
  6.     public $db = 'DB';
  7.    
  8.     public function getName() {
  9.         return $this->name;
  10.     }
  11.    
  12.     public function getEmail() {
  13.         return $this->email;
  14.     }
  15.    
  16.     public function getPassword() {
  17.         return $this->password;
  18.     }
  19.    
  20.     public function form() {
  21.         $form = <<<HTML
  22.         <head>
  23.         <link rel="stylesheet" href="CSS/work_DB.css"/>
  24.         <link href="https://fonts.googleapis.com/css?family=Cormorant|Cormorant+Infant:300,400,500,600,600i|Fira+Sans:100,200,300,400,500,600,700,700i,900|Open+Sans+Condensed:300,300i,700|Open+Sans:300,300i,400,400i,600,600i,700,700i,800&amp;subset=cyrillic" rel="stylesheet"></head>
  25.         <div class="form">
  26.         <form action="" method="post">
  27.         <div class="form-text">
  28.         <h1>Введите ваши даные</h1>
  29.         <div  class="subtitle">Заполните поля для создания вашего аккаунта </div>
  30.         </div>
  31.         <div class="input">
  32.         <input class="place" type="text" name="name"  placeholder="Имя"  value="{$this->name}"> <br>
  33.         <input type="text" name="email"  placeholder="Ел почта"  value="{$this->email}"> <br>
  34.         <input type="password" name="password" placeholder="Пароль"  value="{$this->password}"><br>
  35.         <input class="button"  type="submit" value="Отправить"><br>
  36.         </div>
  37.         </form>
  38.         </div>
  39.         <br><br><br>
  40. HTML;
  41.         return $form;
  42.     }
  43.    
  44.     public function test() {
  45.         if (isset($_POST["name"]) && isset($_POST["email"]) && isset($_POST["password"])) {
  46.             $this->name = $_POST["name"];
  47.             $this->email = $_POST["email"];
  48.             $this->password = $_POST["password"];
  49.             $item = array("name" => $this->name, "email" => $this->email, "password" => $this->password);
  50.             $this->write($item);   
  51.         }  
  52.     }
  53.    
  54.     public function connectDB() {
  55.         $link = mysql_connect($this->host, $this->username, $this->password);
  56.         if (!link) {
  57.             die("Ошибка подключения:" . mysql_error() );
  58.         }
  59.         mysql_select_db($this->db) or die("Не могу найти БД." . mysql_error());
  60.         $this->buildDB();
  61.         return $link;
  62.     }
  63.    
  64.  
  65.     public function buildDB() {
  66.         $sql = 'CREATE TABLE IF NOT EXISTS `registration` (
  67.  `mid` int(11) NOT NULL AUTO_INCREMENT,
  68.  `name` varchar(20) NOT NULL,
  69.  `email` varchar(30) NOT NULL,
  70.  `password` varchar(20) NOT NULL,
  71.  PRIMARY KEY (`mid`)
  72. ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ';
  73.         $result = mysql_query($sql);
  74.         return $result;
  75.     }
  76.    
  77.     public function write($p) {
  78.         $sql = 'INSERT INTO registration(name, email, password) VALUES("'.$p["name"].'", "'.$p["email"].'", "'.$p["password"].'")';
  79.         return mysql_query($sql) or die(mysql_error());
  80.     }
  81.    
  82.     public function display_public() {
  83.         $table = '<table>
  84.         <tr  rowspan="4">
  85.         <th>№</th>
  86.         <th>Ваше имя</th>
  87.         <th>Ваша ел почта</th>
  88.         <th>Ваш пароль</th>
  89.         </tr>
  90.         ';
  91.         $sql = 'SELECT * FROM registration';
  92.         $result = mysql_query($sql);
  93.         while($row = mysql_fetch_array($result)) {
  94.             $table .= '<tr class="post" >
  95.             <td >'.$row['mid'].'</td>
  96.             <td>'.$row["name"].'</td>
  97.             <td>'.$row['email'].'</td>
  98.             <td>'.$row['password'].'</td>
  99.             </tr>';
  100.         }
  101.         $table .= '</table>';
  102.         return $table;
  103.     }
  104.    
  105. }
  106. $obj = new work_DB;
  107. $db_connection = $obj->connectDB();
  108. echo $obj->form();
  109. echo $obj->test();
  110. echo $obj->display_public();
  111. mysql_close($db_connection);
  112. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement