Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class work_DB {
- public $host = 'localhost';
- public $username = 'root';
- public $password = '';
- public $db = 'DB';
- public function getName() {
- return $this->name;
- }
- public function getEmail() {
- return $this->email;
- }
- public function getPassword() {
- return $this->password;
- }
- public function form() {
- $form = <<<HTML
- <head>
- <link rel="stylesheet" href="CSS/work_DB.css"/>
- <link href="https://fonts.googleapis.com/css?family=Cormorant|Cormorant+Infant|Open+Sans+Condensed:300" rel="stylesheet"></head>
- <form action="" method="post">
- <div class="form">
- <div class="form-text">
- <h1>Введите ваши даные</h1>
- <p>Заполните поля для вашего беззопасного доступа на сайт</p>
- </div>
- <div class="input">
- <input class="place" type="text" name="name" placeholder="Имя" value="{$this->name}"> <br>
- <input type="text" name="email" placeholder="Ел почта" value="{$this->email}"> <br>
- <input type="password" name="password" placeholder="Пароль" value="{$this->password}"><br>
- <input class="button" type="submit" value="Отправить"><br>
- </form>
- </div>
- </div><br><br><br>
- HTML;
- return $form;
- }
- public function test() {
- if (isset($_POST["name"]) && isset($_POST["email"]) && isset($_POST["password"])) {
- $this->name = $_POST["name"];
- $this->email = $_POST["email"];
- $this->password = $_POST["password"];
- $item = array("name" => $this->name, "email" => $this->email, "password" => $this->password);
- $this->write($item);
- }
- }
- public function connectDB() {
- $link = mysql_connect($this->host, $this->username, $this->password);
- if (!link) {
- die("Ошибка подключения:" . mysql_error() );
- }
- mysql_select_db($this->db) or die("Не могу найти БД." . mysql_error());
- $this->buildDB();
- return $link;
- }
- public function buildDB() {
- $sql = 'CREATE TABLE IF NOT EXISTS `registration` (
- `mid` int(11) NOT NULL AUTO_INCREMENT,
- `name` varchar(20) NOT NULL,
- `email` varchar(30) NOT NULL,
- `password` varchar(20) NOT NULL,
- PRIMARY KEY (`mid`)
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ';
- $result = mysql_query($sql);
- return $result;
- }
- public function write($p) {
- $sql = 'INSERT INTO registration(name, email, password) VALUES("'.$p["name"].'", "'.$p["email"].'", "'.$p["password"].'")';
- return mysql_query($sql) or die(mysql_error());
- }
- public function display_public() {
- $table = '<table>
- <tr>
- <td>№</td>
- <td>Ваше имя</td>
- <td>Ваша ел почта</td>
- <td>Ваш пароль</td>
- </tr>
- ';
- $sql = 'SELECT * FROM registration';
- $result = mysql_query($sql);
- while($row = mysql_fetch_array($result)) {
- $table .= '<tr class="post">
- <td>'.$row['mid'].'</td>
- <td>'.$row["name"].'</td>
- <td>'.$row['email'].'</td>
- <td>'.$row['password'].'</td>
- </tr>';
- }
- $table .= '</table>';
- return $table;
- }
- }
- $obj = new work_DB;
- $db_connection = $obj->connectDB();
- echo $obj->form();
- echo $obj->test();
- echo $obj->display_public();
- mysql_close($db_connection);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement