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.
<!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
add a comment |
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.
<!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
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
add a comment |
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.
<!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
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.
<!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
php strcmp
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
add a comment |
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
add a comment |
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");
}
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
add a comment |
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");
}
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
add a comment |
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");
}
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
add a comment |
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");
}
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");
}
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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