Reputation: 3110
I've tried looking at other answers, but all I come across is people placing their comparison operators in the wrong direction. Not the case here. Below is a simplified version of my code. This code does not return the error I believe it SHOULD.
I'm trying to determine if a string, in this case a password, meets a minimum length requirement. However, it never gives the error it should, regardless of the string I put in. As a means of debugging, I tried inputting a simple string, "hi" into strlen() and told it to give an error if it was less than 6 bytes long. However, even that wouldn't return as I wanted it to.
I feel like I'm missing something silly. Help?
<?php
$Email = mysql_real_escape_string(Trim($_POST['Email']));
$Password = "hi";
// check fields
$error = false;
if(empty($Email)) $error = true;
if(strlen(utf8_decode($Password)) < 6) $error = true;
if($error != false) header("Location: index.php?error=true");
// store user to database
$success = insert_dbUser(new User($Email, $Password));
// redirect to success page
if ($success) {
header("Location: index.php?success=true");
}
else header("Location: index.php?error=existinguser");
?>
Upvotes: 0
Views: 440
Reputation: 1415
I'd check the syntax of your 'if' statements, as two of them have neither a colon ':' nor curly brackets'{ //do stuff }'. The else needs whatever is to happen 'else' to be in curly brackets. I may be mistaken, but the unusual syntax you have there is what stands out to me. As well as the need for exit statements.
Upvotes: 0
Reputation: 11467
Make sure to end the script after sending location headers:
if ($error) {
header("Location: index.php?error=true");
exit();
}
Upvotes: 3