Link to home
Start Free TrialLog in
Avatar of LB1234
LB1234

asked on

PHP Simple if statement not executing properly

In the following code, all entries result in ""entry must be at least 6 characters" no matter what's entered.  Not sure why this is happening.  Note: value of $max ($max = 6) is in validations file.  Any ideas?  Thanks.

<?php

include ("functions/functions.php");
include ("functions/validations.php");


if (isset($_POST["submit"])) {

$username = $_POST["username"];
$password = $_POST["password"];

	if (empty($username) || empty($password)) {
		$message = "fields are empty";
	
		} if (!is_string($username) || ($password)) {
			$message = "these cannot be numbers";
		
		} if (strlen($username || $password < $max)) {
			$message = "entry must be at least 6 characters";
		
		} else {
			redirect("welcome.php");
	}


} else {

$message = "POST NOT SET";
$username = "";
$password = "";

}


?>




<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>



<?php echo $message ?>
<form action="test.php" method="post">


Enter user name: <input name="username" type="text" value="<?php echo htmlspecialchars($username) ?>"> <br>
Enter password: <input name="password" type="password" value="<?php echo htmlspecialchars($password) ?>"> <br>
<input name="submit" type="submit" id="submit"><br>

</form>





</body>
</html>

Open in new window

SOLUTION
Avatar of Ess Kay
Ess Kay
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of LB1234
LB1234

ASKER

Thanks people.  Can someone explain why mine is incorrect?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of LB1234

ASKER

With the following i get.  line 18 below refers to the strlen statement.

Parse error: syntax error, unexpected T_BOOLEAN_OR in C:\wamp\www\PHP web development\test.php on line 18


	if (empty($username) || empty($password)) {
		$message = "fields are empty";
	
		} if (!is_string($username) || !is_string($password)) {
			$message = "these cannot be numbers";
		
		} if (strlen($username) < $max) || strlen($password) < $max)) {
			$message = "entry must be at least 6 characters";
		
		} else {
			redirect("welcome.php");
	}

Open in new window

Avatar of LB1234

ASKER

Ray that was really awesome!  Wow, much better way!
Avatar of LB1234

ASKER

also I'm using several "if" statements.  Is this bad form? Should i be using if elseif and else statements?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial