There are three php files. index.php (page with the form), verification.php (handler), bd.php (connection to the database).

If I throw all three files right into the root of the site, everything works fine. If I only leave index.php in the root, I place the other two, for example: root >>> php >>> registration >>> and here are two files - Already nothing works.


index.php

 <?php include_once ("bd.php"); ?> <!DOCTYPE html> <html lang="ru"> <head> <meta charset="UTF-8" /> <title>БЛОГ</title> <link rel="stylesheet" href="/css/index.css" type="text/css"/> </head> <body> <div class="wrap"> <form method="post"> <p><input class="input" name="email" type="text" value="Почтовый ящик" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;" /></p> <p><input class="input" name="login" type="text" value="Псевдоним" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;" /></p> <p><input class="input" name="password" type="Password" value="**********" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;" /></p> <p><button name="submit" type="submit" formaction="verification.php" class="button_1">Регистрация</button></p> <p><button type="submit" formaction="Вход.php" class="button_2">Вход</button></p> </form> </div> </body> </html> 

verification.php

 <?php include_once ("bd.php"); if (isset($_POST['submit'])){ if(empty($_POST['login'])) { echo '<br><font color="red">Введите логин! </font>'; } elseif (!preg_match("/^\w{3,}$/", $_POST['login'])) { echo '<br><font color="red">В поле "Логин" введены недопустимые символы! Только буквы, цифры и подчеркивание!</font>'; } elseif(empty($_POST['password'])) { echo '<br><font color="red">Введите пароль!</font>'; } elseif (!preg_match("/\A(\w){6,20}\Z/", $_POST['password'])) { echo '<br><font color="red">Пароль слишком короткий! Пароль должен быть не менее 6 символов!</font>'; } elseif(empty($_POST['email'])) { echo '<br><font color="red">Введите E-mail!</font>'; } elseif (!preg_match("/^[a-zA-Z0-9_\.\-]+@([a-zA-Z0-9\-]+\.)+[a-zA-Z]{2,6}$/", $_POST['email'])) { echo '<br><font color="red">E-mail имеет недопустимий формат! Например, name@gmail.com!</font>'; } else{ $login = $_POST['login']; $password = $_POST['password']; $mdPassword = md5($password); $email = $_POST['email']; $rdate = date("dmY в H:i"); $name = $_POST['name']; $lastname = $_POST['lastname']; $query = ("SELECT id FROM users WHERE login='$login'"); $sql = mysql_query($query) or die(mysql_error()); if (mysql_num_rows($sql) > 0) { echo '<font color="red">Пользователь с таким логином зарегистрирован!</font>'; } else { $query2 = ("SELECT id FROM users WHERE email='$email'"); $sql = mysql_query($query2) or die(mysql_error()); if (mysql_num_rows($sql) > 0){ echo '<font color="red">Пользователь с таким e-mail уже зарегистрирован!</font>'; } else{ $query = "INSERT INTO users (login, password, email, reg_date, name_user, lastname ) VALUES ('$login', '$mdPassword', '$email', '$rdate', '$name', '$lastname')"; $result = mysql_query($query) or die(mysql_error());; echo '<font color="green">Вы успешно зарегистрировались!</font>'; } } } } ?> 

bd.php

 <?php session_start(); mysql_connect ("localhost","radnk2xz_users","654321"); mysql_select_db ("radnk2xz_users"); mysql_query("SET NAMES utf8"); $login = $_SESSION['login']; $password = $_SESSION['password']; $id_user = $_SESSION['id']; ?> 

that works great


And if the root is only index.php, and the remaining two files in a separate folder.

why it does not want to work.

Access denied for user 'radnk2xz' @ 'localhost' (using password: NO)

index.php

 <?php include_once ("php/registration/bd.php"); ?> <!DOCTYPE html> <html lang="ru"> <head> <meta charset="UTF-8" /> <title>БЛОГ</title> <link rel="stylesheet" href="/css/index.css" type="text/css"/> </head> <body> <div class="wrap"> <form method="post"> <p><input class="input" name="email" type="text" value="Почтовый ящик" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;" /></p> <p><input class="input" name="login" type="text" value="Псевдоним" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;" /></p> <p><input class="input" name="password" type="Password" value="**********" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;" /></p> <p><button name="submit" type="submit" formaction="php/registration/verification.php" class="button_1">Регистрация</button></p> <p><button type="submit" formaction="Вход.php" class="button_2">Вход</button></p> </form> </div> </body> </html> 

verification.php

 <?php include_once ("php/registration/bd.php"); if (isset($_POST['submit'])){ if(empty($_POST['login'])) { echo '<br><font color="red">Введите логин! </font>'; } elseif (!preg_match("/^\w{3,}$/", $_POST['login'])) { echo '<br><font color="red">В поле "Логин" введены недопустимые символы! Только буквы, цифры и подчеркивание!</font>'; } elseif(empty($_POST['password'])) { echo '<br><font color="red">Введите пароль!</font>'; } elseif (!preg_match("/\A(\w){6,20}\Z/", $_POST['password'])) { echo '<br><font color="red">Пароль слишком короткий! Пароль должен быть не менее 6 символов!</font>'; } elseif(empty($_POST['email'])) { echo '<br><font color="red">Введите E-mail!</font>'; } elseif (!preg_match("/^[a-zA-Z0-9_\.\-]+@([a-zA-Z0-9\-]+\.)+[a-zA-Z]{2,6}$/", $_POST['email'])) { echo '<br><font color="red">E-mail имеет недопустимий формат! Например, name@gmail.com!</font>'; } else{ $login = $_POST['login']; $password = $_POST['password']; $mdPassword = md5($password); $email = $_POST['email']; $rdate = date("dmY в H:i"); $name = $_POST['name']; $lastname = $_POST['lastname']; $query = ("SELECT id FROM users WHERE login='$login'"); $sql = mysql_query($query) or die(mysql_error()); if (mysql_num_rows($sql) > 0) { echo '<font color="red">Пользователь с таким логином зарегистрирован!</font>'; } else { $query2 = ("SELECT id FROM users WHERE email='$email'"); $sql = mysql_query($query2) or die(mysql_error()); if (mysql_num_rows($sql) > 0){ echo '<font color="red">Пользователь с таким e-mail уже зарегистрирован!</font>'; } else{ $query = "INSERT INTO users (login, password, email, reg_date, name_user, lastname ) VALUES ('$login', '$mdPassword', '$email', '$rdate', '$name', '$lastname')"; $result = mysql_query($query) or die(mysql_error());; echo '<font color="green">Вы успешно зарегистрировались!</font>'; } } } } ?> 

bd.php

 <?php session_start(); mysql_connect ("localhost","radnk2xz_users","654321"); mysql_select_db ("radnk2xz_users"); mysql_query("SET NAMES utf8"); $login = $_SESSION['login']; $password = $_SESSION['password']; $id_user = $_SESSION['id']; ?> 
  • Quite funny ... Notice, you have an error saying 'radnk2xz' @ 'localhost'. That is, the username is clipped to underscore. I honestly do not know why this is happening. Try to escape this lowest underscore. Maybe it will help ... - KryDos
  • sadly ( - Rodion Polyakov
  • So shielding didn't help? - KryDos
  • I am a beginner (I do not know how yet). - Rodion Polyakov
  • And with the help of mysql console it turns out to enter? ( mysql -u radnk2xz_users -p radnk2xz_users ) - dred

2 answers 2

 $root = realpath($_SERVER['DOCUMENT_ROOT']); include_once ($root . "/php/registration/bd.php"); 

strange that no one helped. )))

      <p><button name="submit" type="submit" formaction="verification.php" class="button_1">Регистрация</button></p> 

    Well, if you move files to another folder, then you need to change the path!

    formaction = "php / verification.php"

    • I do so - Rodion Polyakov