Hello, help a newbie.

There is a form of filling data. How to send a user to another page if the registration was successful?

<form action="<?=$_SERVER['PHP_SELF'];?>" method="POST"> Введите логин: <br> <input type="text" name="login"><br> Введите пароль:<br> <input type="text" name="pas"><br> Подтвердите пароль:<br> <input type="text" name="pas_clear"><br> <input type="submit" value="Зарегистрироваться"> </form> 

and the code that processes the form and puts the data into the database:

 <?php ////////////////////////////////////////////// // 1.Проверка правильности заполнения формы // ////////////////////////////////////////////// if($_SERVER['REQUEST_METHOD']=="POST"){ $login = trim($_POST['login']); $pas = trim($_POST['pas']); $pas_clear = trim($_POST['pas_clear']); if (!empty($login) && !empty($pas) && !empty($pas_clear) && $pas==$pas_clear){ ///////////////////////////////////////////////////// // 2. Проверка на наличия уже существования логина // ///////////////////////////////////////////////////// //подключение к базе данных include "blocks/db.php"; $usr = mysql_query("SELECT COUNT(*) FROM user WHERE login = '$login'"); $total = mysql_result($usr, 0); if($total > 0){ exit("Данные логин уже зарегистрирован, пожалуйста, выберите другой."); }elseif($total == 0){ ////////////////////////////////////////////////////////////////// // 3. Регистрируем и заносим в базу логин и пароль пользователя // ////////////////////////////////////////////////////////////////// $usr = "INSERT INTO user VALUES (NULL, '$login', '$pas')"; if (mysql_query($usr)) { echo "</H3>Регистрация прошла успешно</H3>"; echo "<p>Ваш логин: ".$login."\n<br> Ваш пароль: ".$pas."\n<br>Запомните свои данные, а лучше запишите.</p>"; }elseif(!$usr){ exit ("Ошибка при добавлении данных - ".mysql_error()); } } } ?> 

Actually the question is how can you make it so that if everything is entered correctly by the user, then this

 echo "</H3>Регистрация прошла успешно</H3>"; echo "<p>Ваш логин: ".$login."\n<br> Ваш пароль: ".$pas."\n<br>Запомните свои данные, а лучше запишите.</p>";` 

It was displayed on another page without a form, but in case of an error, for example, the password does not match, then output information about it on the same page? The handler on my page is where the form <form action="<?=$_SERVER['PHP_SELF'];?>" method="POST">

Help, please, with an explanation, I will be deeply grateful to all of you. Do not look at security, just writing a function for this.

  • @NoProblems To format a code, select it with the mouse and click on the editor button 101010. - Artem
  • one
    By the way, you have xss there through $ _SERVER ['PHP_SELF'] :) localhost / script.php / "> <script> alert (/ xss /) </ ... > will display / xss /, so shield it with htmlspecialchars () . - tranceman

3 answers 3

 if ($register==true) echo '<meta http-equiv="refresh" content="5; url=http://my-site.ru">'; 

5 is the delay in seconds.

  • thank you so much, it helped to get to another page after registration) just how to display the user's login and password on this page? and it was necessary if ($ total> 0) {exit ("The given login is already registered, please choose another one."); exit change to echo, because if the password is already taken, then using the exit information was displayed on another page, now everything is fine) if you can, still say why? ) - NoProblems
  • to display the username and password on a new page, you can transfer them through the session or you can add get to the url in the meta. url = my-site.ru?login=Vasya&pass=123412341234 on the page output: echo "Login:". $ _ GET ['login']. "<br /> Password:". $ _ GET ['pass']; And at the expense of exit ... I do not understand ... - DemoS
  • one
    Yes, not at all! Just accept the answer if he arranged for you. (To the left of the answer is a tick) - DemoS
  • one
    everything works, thank you))) but there is one BUT ... if I register my login in English, then the login line is visible in English, and if in Russian, then look at this) localhost / test / reg.php? login =% E2% E0% EB% E5% F0% E0 & pas = 123 then login Valera ... is it okay? not because of some encoding? - NoProblems
  • one
    if the resulting page is displayed like this, then yes, because of the encoding. And the fact that the url is spelled this way is normal. The url should not be Cyrillic. You can see for yourself what is happening in the address bar of the browser, when, for example, in Russian search for something to drive in Russian :) - DemoS
 header("Location: http://needUrl.com"); 

But before calling this function there should be no output. I recommend using a buffer.

  • Can you give more details, please? - NoProblems
  • in the beginning of the page you write ob_start (); at the end echo ob_get_clean (); There is output to occur at the end of the script. Those. header () can be used anywhere before "echo" - Vitaly Kustov

in order to avoid conclusions there are jokes with utf-8 save all utf-8 files without BOM!