Jump to content

Why is this code being dificult?


Elusid

Recommended Posts

Why does this work

if($_POST['pass'] == $_POST['passcon']){ die("This is just a test");}

but not this

if($_POST['pass'] != $_POST['passcon']){ die("This is just a test");}

or

if($_POST['pass'] == !$_POST['passcon']){ die("This is just a test");}

or

if($_POST['pass'] <> $_POST['passcon']){ die("This is just a test");}
Link to comment
Share on other sites

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 here

http://evolt.org/article/comment/17/60265/index.html

is 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]
Link to comment
Share on other sites

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...
Link to comment
Share on other sites

!== 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 them
if($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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.