strcmp() not showing proper output (PHP)











up vote
0
down vote

favorite












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");
}
}









share|improve this question
























  • Check for any trailing whitespace character (such as tab, space etc) in either of the two password strings.
    – Madhur Bhaiya
    Nov 11 at 12:36










  • Nope no characters, I tried var_dump($upassword) and var_dump($ucpassword) both of them gave output String(5).
    – malik bagwala
    Nov 11 at 12:39










  • Please extract a Minimal, Complete, and Verifiable example from your code before even posting here. There's way too much code here and the interpretation "strcmp() doesn't work" is not helpful either. As a new user, make sure you read How to Ask and take the tour.
    – Ulrich Eckhardt
    Nov 11 at 12:44










  • You should really be testing for zero(0) since that is what strcmp() returns on a match ... if(strcmp($upassword, $ucpassword) == 0){echo "All cool";}else{echo "Passwords do not Match"}
    – Jamie_D
    Nov 11 at 13:15












  • @Jamie_D This part is alright - if the passwords are different, then terminate the script
    – Markaos
    Nov 11 at 13:17















up vote
0
down vote

favorite












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");
}
}









share|improve this question
























  • Check for any trailing whitespace character (such as tab, space etc) in either of the two password strings.
    – Madhur Bhaiya
    Nov 11 at 12:36










  • Nope no characters, I tried var_dump($upassword) and var_dump($ucpassword) both of them gave output String(5).
    – malik bagwala
    Nov 11 at 12:39










  • Please extract a Minimal, Complete, and Verifiable example from your code before even posting here. There's way too much code here and the interpretation "strcmp() doesn't work" is not helpful either. As a new user, make sure you read How to Ask and take the tour.
    – Ulrich Eckhardt
    Nov 11 at 12:44










  • You should really be testing for zero(0) since that is what strcmp() returns on a match ... if(strcmp($upassword, $ucpassword) == 0){echo "All cool";}else{echo "Passwords do not Match"}
    – Jamie_D
    Nov 11 at 13:15












  • @Jamie_D This part is alright - if the passwords are different, then terminate the script
    – Markaos
    Nov 11 at 13:17













up vote
0
down vote

favorite









up vote
0
down vote

favorite











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");
}
}









share|improve this question















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");
}
}






php strcmp






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 11 at 12:40

























asked Nov 11 at 12:30









malik bagwala

234




234












  • Check for any trailing whitespace character (such as tab, space etc) in either of the two password strings.
    – Madhur Bhaiya
    Nov 11 at 12:36










  • Nope no characters, I tried var_dump($upassword) and var_dump($ucpassword) both of them gave output String(5).
    – malik bagwala
    Nov 11 at 12:39










  • Please extract a Minimal, Complete, and Verifiable example from your code before even posting here. There's way too much code here and the interpretation "strcmp() doesn't work" is not helpful either. As a new user, make sure you read How to Ask and take the tour.
    – Ulrich Eckhardt
    Nov 11 at 12:44










  • You should really be testing for zero(0) since that is what strcmp() returns on a match ... if(strcmp($upassword, $ucpassword) == 0){echo "All cool";}else{echo "Passwords do not Match"}
    – Jamie_D
    Nov 11 at 13:15












  • @Jamie_D This part is alright - if the passwords are different, then terminate the script
    – Markaos
    Nov 11 at 13:17


















  • Check for any trailing whitespace character (such as tab, space etc) in either of the two password strings.
    – Madhur Bhaiya
    Nov 11 at 12:36










  • Nope no characters, I tried var_dump($upassword) and var_dump($ucpassword) both of them gave output String(5).
    – malik bagwala
    Nov 11 at 12:39










  • Please extract a Minimal, Complete, and Verifiable example from your code before even posting here. There's way too much code here and the interpretation "strcmp() doesn't work" is not helpful either. As a new user, make sure you read How to Ask and take the tour.
    – Ulrich Eckhardt
    Nov 11 at 12:44










  • You should really be testing for zero(0) since that is what strcmp() returns on a match ... if(strcmp($upassword, $ucpassword) == 0){echo "All cool";}else{echo "Passwords do not Match"}
    – Jamie_D
    Nov 11 at 13:15












  • @Jamie_D This part is alright - if the passwords are different, then terminate the script
    – Markaos
    Nov 11 at 13:17
















Check for any trailing whitespace character (such as tab, space etc) in either of the two password strings.
– Madhur Bhaiya
Nov 11 at 12:36




Check for any trailing whitespace character (such as tab, space etc) in either of the two password strings.
– Madhur Bhaiya
Nov 11 at 12:36












Nope no characters, I tried var_dump($upassword) and var_dump($ucpassword) both of them gave output String(5).
– malik bagwala
Nov 11 at 12:39




Nope no characters, I tried var_dump($upassword) and var_dump($ucpassword) both of them gave output String(5).
– malik bagwala
Nov 11 at 12:39












Please extract a Minimal, Complete, and Verifiable example from your code before even posting here. There's way too much code here and the interpretation "strcmp() doesn't work" is not helpful either. As a new user, make sure you read How to Ask and take the tour.
– Ulrich Eckhardt
Nov 11 at 12:44




Please extract a Minimal, Complete, and Verifiable example from your code before even posting here. There's way too much code here and the interpretation "strcmp() doesn't work" is not helpful either. As a new user, make sure you read How to Ask and take the tour.
– Ulrich Eckhardt
Nov 11 at 12:44












You should really be testing for zero(0) since that is what strcmp() returns on a match ... if(strcmp($upassword, $ucpassword) == 0){echo "All cool";}else{echo "Passwords do not Match"}
– Jamie_D
Nov 11 at 13:15






You should really be testing for zero(0) since that is what strcmp() returns on a match ... if(strcmp($upassword, $ucpassword) == 0){echo "All cool";}else{echo "Passwords do not Match"}
– Jamie_D
Nov 11 at 13:15














@Jamie_D This part is alright - if the passwords are different, then terminate the script
– Markaos
Nov 11 at 13:17




@Jamie_D This part is alright - if the passwords are different, then terminate the script
– Markaos
Nov 11 at 13:17












1 Answer
1






active

oldest

votes

















up vote
4
down vote



accepted










The problem is here:



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


You are setting $ucpassword to an empty string. It should be like this:



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





share|improve this answer

















  • 1




    Thanks a lot, this did the trick. I highly appreciate your help sir also i marked this as the answer.
    – malik bagwala
    Nov 13 at 5:02











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53248777%2fstrcmp-not-showing-proper-output-php%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
4
down vote



accepted










The problem is here:



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


You are setting $ucpassword to an empty string. It should be like this:



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





share|improve this answer

















  • 1




    Thanks a lot, this did the trick. I highly appreciate your help sir also i marked this as the answer.
    – malik bagwala
    Nov 13 at 5:02















up vote
4
down vote



accepted










The problem is here:



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


You are setting $ucpassword to an empty string. It should be like this:



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





share|improve this answer

















  • 1




    Thanks a lot, this did the trick. I highly appreciate your help sir also i marked this as the answer.
    – malik bagwala
    Nov 13 at 5:02













up vote
4
down vote



accepted







up vote
4
down vote



accepted






The problem is here:



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


You are setting $ucpassword to an empty string. It should be like this:



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





share|improve this answer












The problem is here:



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


You are setting $ucpassword to an empty string. It should be like this:



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






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 11 at 13:14









Markaos

508212




508212








  • 1




    Thanks a lot, this did the trick. I highly appreciate your help sir also i marked this as the answer.
    – malik bagwala
    Nov 13 at 5:02














  • 1




    Thanks a lot, this did the trick. I highly appreciate your help sir also i marked this as the answer.
    – malik bagwala
    Nov 13 at 5:02








1




1




Thanks a lot, this did the trick. I highly appreciate your help sir also i marked this as the answer.
– malik bagwala
Nov 13 at 5:02




Thanks a lot, this did the trick. I highly appreciate your help sir also i marked this as the answer.
– malik bagwala
Nov 13 at 5:02


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53248777%2fstrcmp-not-showing-proper-output-php%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Bressuire

Vorschmack

Quarantine