strcmp () не показывает правильный вывод (PHP) - PullRequest
0 голосов
/ 11 ноября 2018

Так вот мой код, проблема в том, что я получаю вывод strcmp () как 5, когда я ввожу пароль 'malik' в оба поля, когда он, очевидно, должен быть 0, Я приложу изображение, чтобы прояснить ситуацию. Кроме того, я попытался использовать var_dump ($ upassword) и var_dump ($ ucpassword), и я получил String (5) для них обоих, поэтому пробелов нет.

enter image description here

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Sign-UP</title>
</head>
<body>
  <form action="signup.php" method="post">
  <input type="text" name="uname" placeholder="enter the username">
  <input type="email" name="uemail" placeholder="enter the email" id="">
  <input type="password" name="upassword" placeholder="Password">
  <input type="password" name="ucpassword" placeholder="confirm password">
  <button type="submit" name="registor">Registor</button>
  </form>
</body>
</html>
<?php
if (isset($_POST['registor'])) {
  $uname = $_POST['uname'];
  $uemail = $_POST['uemail'];
  $upassword = (string)$_POST['upassword'];
  $ucpassword = (string)$_POST['ucpassword'];
  echo($uname."<br>");
  echo($uemail."<br>");
  echo($upassword."<br>");
  echo($ucpassword."<br>");
  if($uname == '' || $uemail == '' || $ucpassword = '' || $ucpassword = ''){
    die("Please fill all the fields");
  }
  echo(strcmp($upassword,$ucpassword));
  if(strcmp($upassword,$ucpassword) != 0){
    die("Passwords are not the same");
  }
 }

1 Ответ

0 голосов
/ 11 ноября 2018

Проблема здесь:

if($uname == '' || $uemail == '' || $ucpassword = '' || $ucpassword = ''){
  die("Please fill all the fields");
}

Вы устанавливаете $ucpassword в пустую строку. Также вместо первого $ucpassword используйте просто $upassword

Это должно быть так:

if($uname == '' || $uemail == '' || $upassword == '' || $ucpassword == ''){
  die("Please fill all the fields");
}
...