Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- registration.php
- <?php
- $pagetitle = 'Регистрация';
- $templateCurrent = 'templateRegistration.php';
- require_once "templateMain.php";
- $value = array();
- $error = array();
- if (isset($_SERVER['REQUEST_METHOD'])){
- $value['name'] = trim($_POST['name']);
- $value['surname'] = trim($_POST['surname']);
- $value['groupNum'] = trim($_POST['groupNum']);
- $value['points'] = trim($_POST['points']);
- $value['password'] = trim($_POST['password']);
- $value['email'] = trim($_POST['email']);
- switch ($value) {
- case (empty($value['name'])):
- $error['name'] = '1';
- case (empty($value['surname'])):
- $error['surname'] = '1';
- case (empty($value['groupNum'])):
- $error['groupNum'] = '1';
- case (empty($value['points'])):
- $error['points'] = '1';
- case (empty($value['password'])):
- $error['password'] = '1';
- case (empty($value['email'])):
- $error['password'] = '1';
- }
- if (empty($error)){
- $sth = $dbh->prepare("INSERT INTO abitList VALUES ('', ?, ?, ?, ?, ?, ?)");
- $sth->execute(array($value['name'], $value['surname'], $value['groupNum'],
- $value['points'], $value['password'], $value['email']));
- header("Location: /");
- exit();
- }
- }
- function regOutValue($value, $element){
- $value[$element] = isset($value[$element]) ? $value[$element] : '';
- return $value[$element];
- }
- function regOutError($error, $element){
- $error[$element] = isset($error[$element]) ? "*Поле не заполнено" : '';
- return $error[$element];
- }
- templateRegistration.php
- <html>
- <head>
- <link rel="stylesheet" type="text/css" href="/styles.css">
- <meta charset="utf-8">
- </head>
- <body>
- <form action="registration.php" method="post">
- <p><b>Форма регистрации</b></p>
- <?= regOutError($error, 'name') ?>
- <p>Имя: <input type="text" name="name" value="<?=regOutValue($value, 'name')?>"></p>
- <?= regOutError($error, 'surname') ?>
- <p>Фамилия: <input type="text" name="surname" value="<?=regOutValue($value, 'surname')?>"></p>
- <?= regOutError($error, 'groupNum') ?>
- <p>Группа: <input type="text" name="groupNum" value="<?=regOutValue($value, 'groupNum')?>"></p>
- <?= regOutError($error, 'points') ?>
- <p>Баллы: <input type="text" name="points" value="<?=regOutValue($value, 'points')?>"></p>
- <?= regOutError($error, 'password') ?>
- <p>Пароль: <input type='password' name="password" value="<?=regOutValue($value, 'password')?>"></p>
- <?= regOutError($error, 'email') ?>
- <p>Email: <input type='text' name='email' value="<?=regOutValue($value, 'email')?>"></p>
- <p><input type='submit' name='submit' value="Регистрация"></p>
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement