<?php setlocale(LC_ALL, "Rus"); error_reporting(E_ALL); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Practice</title> </head> <body> <?php $dbhost = "localhost"; $dblogin = "mysql"; $dbpass = "mysql"; $dbname = "Login"; $conn = new mysqli($dbhost,$dblogin,$dbpass); mysqli_select_db($conn,$dbname); if ($conn->connect_error) { "Failed to conect".$conn->connect_error(); } ?> <form action="index.php" method="post"> <input type="text" name="name"><br><br> <input type="password" name="pass"><br><br> <input type="email" name="email"><br><br> <input type="submit" name="do_signup"> </form> <?php $data = $_POST; if (isset($_POST['do_signup'])) { $errors = array(); if (trim($data['name']) == '') { $errors[] = "Введите логин"; } if ($data['pass'] == '') { $errors[] = "Введите пароль"; } if (trim($data['email']) == '') { $errors[] = "Введите емаил"; } if (empty($erorrs)) { $name = $data['name']; $pass = $data['pass']; $email = $data['email']; $sql = "INSERT INTO users(user_id,user_name,user_pass,user_email) VALUES (NULL,'$name','$pass','$email')"; $conn->query($sql); }else{ echo "<div id='errors' style='color:red;'>".array_shift($errors)."</div>"; }} ?> 

Please tell me why the check does not work. Sends even null values

Closed due to the fact that it was off-topic by the participants Kostiantyn Okhotnyk , PashaPash 16 Sep '17 at 12:06 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • "The question is caused by a problem that is no longer reproduced or typed . Although similar questions may be relevant on this site, solving this question is unlikely to help future visitors. You can usually avoid similar questions by writing and researching a minimum program to reproduce the problem before publishing the question. " - PashaPash
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • Isn't it easier to check for empty() ? - user242433
  • So easy to read - Orest Ganulyak
  • Try with empty() , I am sure that the problem is under these conditions ( if ($data['pass'] == '')... - user242433
  • Yes, now it does not send, but another problem has appeared, it does not display errors, can you tell me how to fix it ??? - Orest Ganulyak

1 answer 1

you have a typo if (empty ($ erorrs)) instead of if (empty ($ errors))

  • Everything worked, thanks to all - Orest Ganulyak