1

Тема: Дуже потрібна ваша допомога!!

Я зробив перевірку полів при реєстрації! І тут є невеличка проблемка *PARDON*:  всі поля перевіряються, але якщо поле перше перевірилось і виявилась якась помилка, то появляється віконечко ! І дальше якщо перезагружати сторінку чи повторно відсилати форму, то воно лишається!
Файл user.php

<?php 
echo "<meta charset='utf-8'>";
    class User{
    public $firstname;
    public $lastname;
    public $login = "";
    public $password;
    public $re_password;
    public $email;
    public $birthday;
    public $sex;
    public $phone;
    public $country;
    public $region;
    public $city;
    public $adress;
    public function serch_error(){
    
    $login = clear_string($this->login);
    $email = clear_string($this->email);
    $pass = clear_string($this->password);
    $re_pass = clear_string($this->re_password);
    $result = mysql_query("select * from users");
    if($this->login != ""){
    $rows = mysql_num_rows($result);
    $message = "";
    
    $num_errors = 0;
    
    for($i = 0;$i < $rows; $i++){
        $row = mysql_fetch_row($result);
        
        if($email == $row[5]){
            $num_errors++;
            $message .= $num_errors.". Такий e-mail вже використовується!";
        }
        if($login == $row[3]){
            if($num_errors > 0){
                $message .= "<br>";
            }
            ++$num_errors;        
            $message .= $num_errors.". Такий login вже використовується!";
        }
    }
    if($pass != $re_pass){
        if($num_errors > 0){
            $message .= "<br>";
        }
        ++$num_errors;        
        $message .= $num_errors.". Паролі не співпадають!";
    }
    return $message;    
        }
    }
    public function save_user(){
        
        $query = "insert into `users` (`firstname`, `lastname`, `login`, `password`, `email`, `birthday`, `sex`, `phone`, `country`, `region`, `sity`, `adress`) values ('".$this->firstname."','".$this->lastname."','".$this->login."','".md5($this->password)."','".$this->email."','".$this->birthday."','".$this->sex."','".$this->phone."','".$this->country."','".$this->region."','".$this->city."','".$this->adress."');";
        $result = mysql_query($query);
        echo mysql_error();
    }
    }

    

Файл sign_up.php

<?php include("functions.php");
$user = new User;
$user->firstname = $_POST['firstname'];
$user->lastname = $_POST['lastname'];
$user->login = $_POST['login'];
$user->email = $_POST['email'];
$user->password = $_POST['password'];
$user->sex = $_POST['sex'];
$user->re_password = $_POST['re-password'];
$user->birthday = $_POST['birthday'];
$user->phone = $_POST['phone'];
$user->country = $_POST['country'];
$user->region = $_POST['region'];
$user->city = $_POST['city'];
$user->adress = $_POST['street']; 
if($user->serch_error() == ""){
    $user->save_user();
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<link rel="stylesheet" href="/style.css">

</head>
<body>

<article>
<?php include("block/header.php");?>

<div id="sitebar">
d

</div>
<div id="content">

<center><h1>Реєстрація користувача<?php if($name_true == true) echo": ".$_POST['firstname']." ".$_POST['lastname']?></h1></center>
<form id="sign_up_form"   method="post" >
<table cellpadding="0" cellspacing="0">
    <tr>
        <td>
        <input type="text" name="firstname" placeholder="Ім'я" required  <?php if($name_true == true){echo("readonly value='".$_POST['firstname']."'");}?>>
        <input type="text" name="lastname" placeholder="Прізвище" required  <?php if($name_true == true){echo("readonly value='".$_POST['lastname']."'");}?>><br>
        <input type="email" name="email" placeholder="E-mail" required>
        <input type="text" name="login" placeholder="Логін" required><br>
        <input type="password" name="password" placeholder="Пароль" required>
        <input type="password" name="re-password" placeholder="Ще раз пароль" required>
        </td>
        <td>
        Виберіть стать:
        <select name="sex">        
        <option value="man">Чоловік</option>
        <option value="woman">Жінка</option>
        </select><br>
        
        <input type="checkbox" name="confirm" value="ok" required> Я приймаю <a href="/rules.php" TARGET="_blank">Правила користування сайтом</a>!
       
        </td>
         
    </tr>
    <tr> 
        <td> 
           <input type="tel" name="phone" placeholder="Мобільний номер" required>
        <input type="date" name="birthday" placeholder="Дата народження"  required>
        <input type="text" name="country" placeholder="Країна" required>
        <input type="text" name="region" placeholder="Область" required>
        <input type="text" name="city" placeholder="Населений пункт" required>
        <input type="text" name="street" placeholder="Вул., буд., кв." required>
        
        </td>
        <? if($user->serch_error() != ""){echo
        "<th id='message'>".$user->serch_error()."</th>";
        
        }
        elseif($user->serch_error() == "") echo "<td>Успішна реєстрація</td>";
        
        ?>
    </tr>
    
    <center><input type="submit" name="submit_sign" value="Зареєструватися"></center>
        



<table>
</form>


</div>
</article>

</body>
</html>

Буду дуже вдячний якщо допоможете!

Post's attachments

Screenshot_1.png 35.37 kb, 132 downloads since 2016-08-13 

2

Re: Дуже потрібна ваша допомога!!

Це тому, що при простому перезавантаженні сторінки стан POST запиту у вас зберігається.
Вам потрібно обнулити/знищити попередній POST запит, щоб при наступному релоаді не надсилалися ті ж дані.
Можете навіть писати помилки в
//session_start(); не забудьте
$_SESSION['error'] = 'помилка'; , далі
die(header('Location: ?')); //редірект на сторінку реєстрації, після цього стан POST запиту знищується.
Далі виводите помилки з сессії і відразу видаляєте ту сессію, щоб при наступному релоаді чи чогось ще, її вже не було.
unset($_SESSION['error']);

Подякували: 221VOLT1