duanjianhe1388 2018-11-11 12:30 采纳率: 100%
浏览 82
已采纳

strcmp()没有显示正确的输出(PHP)

So here is my code, the problem is that i get strcmp() output as 5 when i enter the password 'malik' in both the fields when it should obviously be 0, i will attach an image to make myself clear. Also, I tried using var_dump($upassword) and var_dump($ucpassword) and I got String(5) for both of them, so there are no whitespaces.

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条回答 默认 最新

  • douran6443 2018-11-11 13:14
    关注

    The problem is here:

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

    You are setting $ucpassword to an empty string. Also instead of first $ucpassword use just $upassword

    It should be like this:

    if($uname == '' || $uemail == '' || $upassword == '' || $ucpassword == ''){
      die("Please fill all the fields");
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 怎样才能让鼠标沿着线条的中心线轨迹移动
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?