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 = "mydb";
- public function getName() {
- return $this->name;
- }
- public function getEmail() {
- return $this->email;
- }
- public function getPassword() {
- return $this->password;
- }
- public function form() {
- $form = <<<HTML
- <form action=" " method="post">
- <p>Введите ваши даные</p><br><br>
- <label>Имя</label><br>
- <input type="text" name="name" value="{$this->name}"><br><br>
- <label>Ел почта</label><br>
- <input type="text" name="email" value="{$this->email}"><br><br>
- <label>Пароль</label><br>
- <input type="password" name="password" value="{$this->password}"><br><br>
- <input type="submit" value="Отправить">
- </form>
- 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"];
- $kotya = array("name" => "$this->name", "email" => "$this->email", "password" => "$this->password");
- $this->write($kotya);
- }
- }
- 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) DEFAULT NULL,
- `email` varchar(30) DEFAULT NULL,
- `password` varchar(20) DEFAULT NULL,
- PRIMARY KEY (`mid`)
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ';
- $result = mysql_query($sql);
- echo $result;
- }
- public function write($p) {
- $sql = 'INSERT INTO registration(name, email, password) VALUES("'.$p["name"].'", "'.$p["email"].'", "'.$p["password"].'")';
- return mysql_query($sql);
- }
- public function display_public() {
- $sql = 'SELECT * FROM registration';
- $result = mysql_query($sql) or die (mysql_error());
- echo $table = "<table>
- <tr>
- <td>номер</td>
- <td>имя</td>
- <td>ел почта</td>
- <td>пароль</td>
- </tr>";
- 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;
- }
- }
- $obj1 = new work_DB;
- $db_connection = $obj1->connectDB();
- echo $obj1->form();
- echo $obj1-> test();
- echo $obj1->display_public();
- mysql_close($db_connection);
- ?>
Add Comment
Please, Sign In to add comment