Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: HTML PHP find
I have a program set to get variables from a page,
and compare them. If the variable $password does not
match $repassword then it will echo an error. It echo's
the error no matter what, please help
 
The html page code is:
 
eeWebHostingArea
Site made by 42cheese Team
Contact us at: hdesk@42cheese.6te.net
 

 
<html>
<head>
<title>Happycraft Survival and Creative</title>
 

#foreground
{
padding: 5px;
border-radius: 25px; 
-moz-border-radius: 25px; 
-webkit-border-radius: 25px; 
border: 1px solid blue;
background-color: red;
color: green:
}
 
#navbar
{
background-color: brown;
padding: 5px;
border-radius: 25px; 
-moz-border-radius: 25px; 
-webkit-border-radius: 25px; 
}
 
.nav
{
background-color: red;
border-radius: 50px; 
-moz-border-radius: 50px; 
-webkit-border-radius: 50px; 
border: 1px solid blue;
text-decoration: none;
color: blue;
padding: 2px;
}
 
#body
{
background-color: red;
color: blue;
}
 
#thnx
{
text-align: right;
color: black;
}
 
#thnx a
{
text-decoration: none;
color: black;
}
 

</head>
<body>
 

<marquee style="background-color: red; color: blue; margin-left: 5px; margin-right: 5px;" direction="left" loop="-1" width="99%">
Be Happy!
</marquee>
 

Home
Apply
 

Register:
<form method=POST action="registerphp.php">
Username:
<input type="text" name="name">
 
Password:
<input type="password" name="pass">
 
Repeat Password:
<input type="password" name="repass">
 
<input type="submit" value="Submit">
</form>
 

  
  <script language="JavaScript">
  var data = '&r=' + escape(document.referrer)
	+ '&n=' + escape(navigator.userAgent)
	+ '&p=' + escape(navigator.userAgent)
	+ '&g=' + escape(document.location.href);
 
  if (navigator.userAgent.substring(0,1)>'3')
    data = data + '&sd=' + screen.colorDepth 
	+ '&sw=' + escape(screen.width+'x'+screen.height);
 
  document.write('');
  document.write('');
  document.write('');
  </script>
 
Free site hosting and subdomain byFreeWebHostingArea
Site made by 42cheese Team
Contact us at: hdesk@42cheese.6te.net
 

 
</body>
</html>
 
PHP Code:
 
Back");
 
}
 
if(!$password == $repassword)
{
 
die("Password Does Not MatchBack");
 
}
 
$query = mysql_query("INSERT INTO happylogin(name,password) VALUES('{$ename}','{$epassword}'");
 
if($query)
{
echo"Account Created SuccessfullyHome";
$query = mysql_query("SELECT * FROM happylogin WHERE name='$ename'");
$array = mysql_fetch_array($query);
$_SESSION['ID'] = $array['ID'];
 
$_SESSION['name'] = $name;
}
 
else
{
die("Error Creating AccountCheck Internet Connection or Contact the 42cheese Team at hdesk@42cheese.6te.net");
}
 

?>
-AKsicppy
Posted 10-Dec-11 21:06pm
Sicppy1.5K
Edited 11-Dec-11 15:55pm
v3
Comments
thatraja at 11-Dec-11 2:41am
   
what's the error message?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

you can try this:
<?php
if($password == $repassword)
{
   $query = mysql_query("INSERT INTO happylogin(name,password) VALUES('   {$ename}','{$epassword}'");
 
 if($query)
 {
  echo"Account Created SuccessfullyHome";
  $query = mysql_query("SELECT * FROM happylogin WHERE  name='$ename'");
 $array = mysql_fetch_array($query);
 $_SESSION['ID'] = $array['ID'];
 
  $_SESSION['name'] = $name;
 }
 
 else
 {
 die("Error Creating AccountCheck Internet Connection or Contact the  42cheese Team at hdesk@42cheese.6te.net");
 
 }
}
else
{
 die("Password Does Not MatchBack");
 
}
?>
 
hope it helps Smile | :)
  Permalink  
v2
Comments
Monjurul Habib at 11-Dec-11 20:51pm
   
5!
Uday P.Singh at 12-Dec-11 4:18am
   
thank you Monjurul :)
LanFanNinja at 11-Dec-11 21:27pm
   
+5
Uday P.Singh at 12-Dec-11 4:18am
   
thank you LanFanNinja :)
Sicppy at 2-Jul-12 4:31am
   
I haven't got to try your response yet, i have been busy the past few months with some projects I've been working on, but by the looks of the comments it seems to have worked for some other people, I'll give it a shot and get back to you soon,
 
Thanks
 
-Jordan
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I'm not a php Dev, but in any other language I use
if(!$password == $repassword) is the same as if( (!$password) == $repassword) 
 
i.e. !password evaluates first and then is compared with $repassword
 
try using
 
if( ! ($password == $repassword )) 
 
Regards
 
Richard
  Permalink  
v2
Comments
Sicppy at 11-Dec-11 2:57am
   
I am afraid to say it didn't work, thanks for your response though,
-AKsicppy
Monjurul Habib at 11-Dec-11 20:51pm
   
5!
LanFanNinja at 11-Dec-11 21:17pm
   
+4 Correct or better yet
if ($password != $repassword)
or
if ($password !== $repassword)
 
However you are correct this code
 
if (!$password == $repassword)
 
Is straight up WRONG! Using this code the passwords will always match unless one of the strings are empty ("").
 
for example
$pass = "I am BIG bird";
$rePass = "dog";
 
if (!$pass == $rePass)
{
echo $pass." and ".$rePass." do not match!";
}
else
{
echo "Match";
}
 
this code will always echo Match.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 11 Dec 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100