Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
<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:
PHP
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
Updated 11-Dec-11 14:55pm
v3
Comments
thatraja 11-Dec-11 2:41am    
what's the error message?

you can try this:
PHP
<?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 :)
 
Share this answer
 
v2
Comments
Monjurul Habib 11-Dec-11 20:51pm    
5!
Uday P.Singh 12-Dec-11 4:18am    
thank you Monjurul :)
LanFanNinja 11-Dec-11 21:27pm    
+5
Uday P.Singh 12-Dec-11 4:18am    
thank you LanFanNinja :)
Sicppy 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
I'm not a php Dev, but in any other language I use
PHP
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
 
Share this answer
 
v2
Comments
Sicppy 11-Dec-11 2:57am    
I am afraid to say it didn't work, thanks for your response though,
-AKsicppy
Monjurul Habib 11-Dec-11 20:51pm    
5!
LanFanNinja 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900