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 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员