PHPMine
<? if(PHP > $Expectations) echo $Results ?>
by Angel S. Moreno
UNDER SOME SERIOUS CONSTRUCTION LINKS MAY NOT WORK
Asked 2010-03-07 21:12:35 by 24JJ24
Hi,
I have an if/else clause to figure out whether a string entered is above 6 characters. For some reason its coming back as an error if there are 5 or less characters, but it is not accepting that 6+ characters is fine for some reason. This is probably a silly mistake but I can't seem to figure it out.
<tr>
<td><div class="<?php print $pass1empty; ?>">Password:*</div></td>
<td><input type="password" maxlength="32" name="Password1" value="<?php print $passone; ?>" size="30"/></td>
</tr>
<tr>
<td><div class="<?php print $pass2empty; ?>">Confirm Password:*</div></td>
<td><input type="password" maxlength="32" name="Password2" value="<?php print $passtwo; ?>" size="30"/></td>
</tr>
<?php
//Password Length Check
if (strlen($passone < 5) || strlen($passone == 5)){
$pass1empty="errortext";
$pass2empty="errortext";
$passlength1error = "NOTOK";
$flag11="NOTOK";
}
else if (strlen($passone == 6) || strlen($passone > 6)){
$pass1empty="basictext";
$pass2empty="basictext";
$passlength1error = "OK";
$flag11="OK";
}
//Password Confirm, Length Check
if (strlen($passtwo < 5) || strlen($passtwo == 5)){
$pass1empty="errortext";
$pass2empty="errortext";
$passlength2error = "NOTOK";
$flag12="NOTOK";
}
else if (strlen($passtwo == 6) || strlen($passtwo > 6)){
$pass1empty="basictext";
$pass2empty="basictext";
$passlength2error = "OK";
$flag12="OK";
}
if ($_POST['process'] == 1) {
if (empty($passone) || empty($passtwo)){
$pass1empty="errortext";
$pass2empty="errortext";
print '<tr><td align="center" colspan="2" class="errorsubtext"> Please enter a password. </td></tr>';
}
else if (($passlength1error == "NOTOK") || ($passlength2error == "NOTOK")){
$pass1empty="errortext";
$pass2empty="errortext";
$flag = "NOTOK";
print '<tr><td align="center" colspan="2" class="errorsubtext"> The password you entered is not long enough. </td></tr>';
}
else if (($passlength1error == "OK") && ($passlength2error == "OK")){
$pass1empty="basictext";
$pass2empty="basictext";
$flag = "OK";
}
}
Some of the form is missing, but this is the main part where the variables are defined and the if/else is formed.
Thanks
Problem solved, thank you, thank you, thank you!!
Anwered 2010-03-07 21:27:30 by Colanth
Same thing for the first one:
if (strlen($passone < 5) || strlen($passone == 5))
should be
if ((strlen($passone) < 5) || (strlen($passone) == 5))
Actually, it should be
if (strlen($passone) <= 5)
The else if (strlen($passone == 6) || strlen($passone > 6)) can be just else. If it's not <=5 it's 6 or more.
Anwered 2010-03-07 21:23:29 by squash
instead of having
if(strlen($passtwo == 6) )
you have to write it like this:
if( strlen($passtwo) == 6 )
try that and see if it works.
Questions and answers provided by the Yahoo Answers Community.