Elusid Posted August 8, 2006 Share Posted August 8, 2006 Why does this workif($_POST['pass'] == $_POST['passcon']){ die("This is just a test");}but not thisif($_POST['pass'] != $_POST['passcon']){ die("This is just a test");}orif($_POST['pass'] == !$_POST['passcon']){ die("This is just a test");}or if($_POST['pass'] <> $_POST['passcon']){ die("This is just a test");} Quote Link to comment Share on other sites More sharing options...
tomfmason Posted August 8, 2006 Share Posted August 8, 2006 for your second one try this[code=php:0]if ($_POST['pass'] !== $_POST['passcon']) { or die("Your passwords do not match");}[/code]About the last one I have no idea.Hope this helps,Tom Quote Link to comment Share on other sites More sharing options...
Elusid Posted August 8, 2006 Author Share Posted August 8, 2006 Hmmmm nope I still get the error message that this file makes if something goes wrong... here is the full file and the only things that are changed basicly all that is changed from the origonal which can be found herehttp://evolt.org/article/comment/17/60265/index.htmlis this[code] if(!$_POST['user'] || !$_POST['pass'] || !$_POST['passcon']){ die('You didn\'t fill in a required field.'); }if($_POST['pass'] !== $_POST['passcon']){ die("This is just a test");}[/code]and this[code]<tr><td><input type="password" name="passcon" maxlength="30"></td></tr>[/code]Other then that it's all the same so somthing is going wrong... The origonal works great! But this...[code]<?session_start(); function usernameTaken($username){ global $conn; if(!get_magic_quotes_gpc()){ $username = addslashes($username); } $q = "select username from users where username = '$username'"; $result = mysql_query($q,$conn); return (mysql_numrows($result) > 0);}function addNewUser($username, $password){ global $conn; $q = "INSERT INTO users VALUES ('$username', '$password')"; return mysql_query($q,$conn);}function displayStatus(){ $uname = $_SESSION['reguname']; if($_SESSION['regresult']){?><html><body bgcolor='000000' text='ffffff' link='ff0000' vlink='880000'><h1>Registered!</h1><p>Thank you <b><? echo $uname; ?></b>, your information has been added to the database, you may now <a href="main.php" title="Login">log in</a>.</p></body></html><? } else{?><html><body bgcolor='000000' text='ffffff' link='ff0000' vlink='880000'><h1>Registration Failed</h1><p>We're sorry, but an error has occurred and your registration for the username <b><? echo $uname; ?></b>, could not be completed.<br>Please try again at a later time.</p></body></html><? } unset($_SESSION['reguname']); unset($_SESSION['registered']); unset($_SESSION['regresult']);}if(isset($_SESSION['registered'])){?><html><title>Registration Page</title><body><? displayStatus(); ?></body></html><? return;}if(isset($_POST['subjoin'])){ if(!$_POST['user'] || !$_POST['pass'] || !$_POST['passcon']){ die('You didn\'t fill in a required field.'); }if($_POST['pass'] !== $_POST['passcon']){ die("This is just a test");} $_POST['user'] = trim($_POST['user']); if(strlen($_POST['user']) > 30){ die("Sorry, the username is longer than 30 characters, please shorten it."); } if(usernameTaken($_POST['user'])){ $use = $_POST['user']; die("Sorry, the username: <strong>$use</strong> is already taken, please pick another one."); } $md5pass = md5($_POST['pass']); $_SESSION['reguname'] = $_POST['user']; $_SESSION['regresult'] = addNewUser($_POST['user'], $md5pass); $_SESSION['registered'] = true; echo "<meta http-equiv=\"Refresh\" content=\"0;url=$HTTP_SERVER_VARS[PHP_SELF]\">"; return;}else{?><html><title>Registration Page</title><body bgcolor='000000' text='ffffff' link='ff0000' vlink='880000'><h1>Register</h1><form action="<? echo $HTTP_SERVER_VARS['PHP_SELF']; ?>" method="post"><table align="left" border="0" cellspacing="0" cellpadding="3"><tr><td>Username</td></tr><tr><td><input type="text" name="user" maxlength="30"></td></tr><tr><td>Password</td></tr><tr><td><input type="password" name="pass" maxlength="32"></td></tr><tr><td>Re-type Password</td></tr><tr><td><input type="password" name="passcon" maxlength="30"></td></tr><tr><td colspan="2" align="right"><input type="submit" name="subjoin" value="Join!"></td></tr></table></form></body></html><?}?>[/code] Quote Link to comment Share on other sites More sharing options...
king arthur Posted August 8, 2006 Share Posted August 8, 2006 So basically you're saying it doesn't execute the die() function even if the passwords entered are different? Quote Link to comment Share on other sites More sharing options...
Elusid Posted August 8, 2006 Author Share Posted August 8, 2006 Yes it just displays this<h1>Registration Failed</h1><p>We're sorry, but an error has occurred and your registration for the username <b><? echo $uname; ?></b>, could not be completed.<br>Please try again at a later time.</p>but if I do the die command with it == insted of !== it displays it just fine when the passwords are the same... Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted August 8, 2006 Share Posted August 8, 2006 !== compares wheather the two values are the same type not whether they are the same. Take this for example:[code=php:0]// var1 is an integer$var1 = 500;// var2 is a string$var2 = '500';//now we compare themif($var1 !== $var2){ echo "They are not the same type!!";}else{ echo "They are the same!!";}[/code]You'll want to use != which doesnt compare whether they are same type. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.