strcmp() 未显示正确的输出 (PHP)
strcmp() not showing proper output (PHP)
所以这是我的代码,问题是当我在两个字段中输入密码 'malik' 时,我得到的 strcmp() 输出为 5,而密码显然应该为 0,
我会附上一张图片让自己清楚。另外,我尝试使用 var_dump($upassword) 和 var_dump($ucpassword) 并且我为它们都得到了 String(5),所以没有空格。
<!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");
}
}
问题出在这里:
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");
}
所以这是我的代码,问题是当我在两个字段中输入密码 'malik' 时,我得到的 strcmp() 输出为 5,而密码显然应该为 0, 我会附上一张图片让自己清楚。另外,我尝试使用 var_dump($upassword) 和 var_dump($ucpassword) 并且我为它们都得到了 String(5),所以没有空格。
<!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");
}
}
问题出在这里:
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");
}