Advertisement
Guest User

Untitled

a guest
Jun 20th, 2016
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.67 KB | None | 0 0
  1. registration.php
  2. <?php
  3.  
  4. $pagetitle = 'Регистрация';
  5. $templateCurrent = 'templateRegistration.php';
  6. require_once "templateMain.php";
  7.  
  8. $value = array();
  9. $error = array();
  10.  
  11. if (isset($_SERVER['REQUEST_METHOD'])){
  12.  
  13.     $value['name'] = trim($_POST['name']);
  14.     $value['surname'] = trim($_POST['surname']);
  15.     $value['groupNum'] = trim($_POST['groupNum']);
  16.     $value['points'] = trim($_POST['points']);
  17.     $value['password'] = trim($_POST['password']);
  18.     $value['email'] = trim($_POST['email']);
  19.  
  20.     switch ($value) {
  21.         case (empty($value['name'])):
  22.             $error['name'] = '1';
  23.         case (empty($value['surname'])):
  24.             $error['surname'] = '1';   
  25.         case (empty($value['groupNum'])):
  26.             $error['groupNum'] = '1';  
  27.         case (empty($value['points'])):
  28.             $error['points'] = '1';
  29.         case (empty($value['password'])):
  30.             $error['password'] = '1';
  31.         case (empty($value['email'])):
  32.             $error['password'] = '1';  
  33.     }
  34.  
  35.     if (empty($error)){
  36.         $sth = $dbh->prepare("INSERT INTO abitList VALUES ('', ?, ?, ?, ?, ?, ?)");
  37.         $sth->execute(array($value['name'], $value['surname'], $value['groupNum'],
  38.                             $value['points'], $value['password'], $value['email']));
  39.         header("Location: /");
  40.         exit();
  41.     }
  42.    
  43. }
  44.  
  45. function regOutValue($value, $element){
  46.  
  47.         $value[$element] = isset($value[$element]) ? $value[$element] : '';
  48.  
  49.         return $value[$element];
  50. }
  51.  
  52. function regOutError($error, $element){
  53.  
  54.         $error[$element] = isset($error[$element]) ? "*Поле не заполнено" : '';
  55.  
  56.         return $error[$element];
  57. }
  58.  
  59.  
  60.  
  61. templateRegistration.php
  62. <html>
  63. <head>
  64.     <link rel="stylesheet" type="text/css" href="/styles.css">
  65.     <meta charset="utf-8">
  66. </head>
  67. <body>
  68.  
  69. <form action="registration.php" method="post">
  70.     <p><b>Форма регистрации</b></p>
  71.  
  72.     <?= regOutError($error, 'name') ?>
  73.     <p>Имя: <input type="text" name="name" value="<?=regOutValue($value, 'name')?>"></p>
  74.  
  75.     <?= regOutError($error, 'surname') ?>
  76.     <p>Фамилия: <input type="text" name="surname" value="<?=regOutValue($value, 'surname')?>"></p>
  77.  
  78.     <?= regOutError($error, 'groupNum') ?>
  79.     <p>Группа: <input type="text" name="groupNum" value="<?=regOutValue($value, 'groupNum')?>"></p>
  80.  
  81.     <?= regOutError($error, 'points') ?>
  82.     <p>Баллы: <input type="text" name="points" value="<?=regOutValue($value, 'points')?>"></p>
  83.  
  84.     <?= regOutError($error, 'password') ?>
  85.     <p>Пароль: <input type='password' name="password" value="<?=regOutValue($value, 'password')?>"></p>
  86.  
  87.     <?= regOutError($error, 'email') ?>
  88.     <p>Email: <input type='text' name='email' value="<?=regOutValue($value, 'email')?>"></p>
  89.  
  90.     <p><input type='submit' name='submit' value="Регистрация"></p>
  91. </form>
  92.  
  93. </body>
  94. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement