Jump to content

If statement not working, really weird, someone help!


Mythic Fr0st

Recommended Posts

I was having problems on signup page, for validating on the spot, so im doing it on the next page...

However some reason

[code]if (!strlen('user') > 5)
{
( These actions send mail with activation code n details )
}
else
{
echo '<font color="blue" size="4">Error:</font><font color="blue" size="3"><i> Your username must be no less than 5 characters</i></font>';
}[/code]

some reason it only works when its if (!strlen('user') > 5), and not if (!strlen('user') < 5)

yet im wanting to check if if (!strlen('user') is less than 5)

firstly, user is the name of the Username text box I have,

if I enter nothing, it appears, even with 4 characters, it appears and says, too short or whatever,

HOWEVER soon as I put say 5-60 digit username, it still says it O_O?

I cant figure this out

Code
( It starts at IF (!strlen('user') < 5)
[code]<html>
<head>
<style type="text/css">
body
{
background-image:
url('SilverBG.jpg')
}
</style>
</head>
<img src="Gaming Ink Banner.jpg" width="1008" height="125">
<div align='center'>
<body>
<?php
if (!strlen('user') > 5)
{
$email[1]=$_POST['email1'];
$email[2]=$_POST['email2'];
$pw[1]=$_POST['pw1'];
$pw[2]=$_POST['pw2'];
$bool[1]=true;
$bool[2]=true;
if ($email[1] == $email[2])
{
echo " <b>Your e-mail's match</b> <br/>";
}
else
{
echo "<b><font color='darkblue' size='4'>Your e-mail's do not match</font></b></br>";
$bool[1]=false;
}

if ($pw[1] == $pw[2])
{
echo "<b>Your passwords match</b>";
}
else
{
echo "<b><font color='darkred' size='4'>Your password's do not match</font></b>";
$bool[2]=false;
}

if ($bool[1] == true && $bool[2] == true)
{
$msg='<font color="darkred" size="4">Welcome to Mythic Aeons</font>';
$subject='Activation Code';
$from='MythicAeons@yahoo.com.au';
$headers='From: '.$from;
mail($_POST['email1'],$subject,$msg,$headers);
echo '<font color="blue" size="4">Your details have been e-mailed to you</font>';
}
}[/color]
else[/color]
{[/color]
echo '<font color="blue" size="4">Error:</font><font color="blue" size="3"><i> Your username must be no less than 5 characters</i></font>';
}(ENDS HERE)

?>
</body>
</html>
[/code]


Someone please help, i've spent hours trying to get this, it just wont WORK! GRR
Link to comment
Share on other sites

Im wanting to check, if the length of the text in the Username text box on my signup page is less than 5, if so, display the error "Your username must be atleast 5 characters"

else

( Actions for mailing )

oh btw, I wanna make more IF statements, so to check if username's not anymore char's than 18,

( Display error )

else

(mail actions )

To also check if password is less than 5,

( display error )

to check if password is greater than 18,

(display the error)

can you help me with that O_O?

ive only learnt php for the past uhhm 15 hours or so


I edited again, and changed what you said ( I think )

heres edit
if i use the " > " thing, it never works, long or little characters
if I use the " < " thing, it always works, long or little chars :(

[code]<?php
$USR=$_POST['user'];
if (!strlen($USR) < 5)
{
echo '<font color="blue" size="4">Error:</font><font color="blue" size="3"><i> Your username must be no less than 5 characters</i></font>';
}
else
{
$email[1]=$_POST['email1'];
$email[2]=$_POST['email2'];
$pw[1]=$_POST['pw1'];
$pw[2]=$_POST['pw2'];
$bool[1]=true;
$bool[2]=true;
if ($email[1] == $email[2])
{
echo " <b>Your e-mail's match</b> <br/>";
}
else
{
echo "<b><font color='darkblue' size='4'>Your e-mail's do not match</font></b></br>";
$bool[1]=false;
}

if ($pw[1] == $pw[2])
{
echo "<b>Your passwords match</b>";
}
else
{
echo "<b><font color='darkred' size='4'>Your password's do not match</font></b>";
$bool[2]=false;
}

if ($bool[1] == true && $bool[2] == true)
{
$msg='<font color="darkred" size="4">Welcome to Mythic Aeons</font>';
$subject='Activation Code';
$from='MythicAeons@yahoo.com.au';
$headers='From: '.$from;
mail($_POST['email1'],$subject,$msg,$headers);
echo '<font color="blue" size="4">Your details have been e-mailed to you</font>';
}
}


?>[/code]
Link to comment
Share on other sites

The " > " 'thing' is the greater than comparison operator. The " < " is the less than comparison operator. You want to issue the error if the username entered is less than 5 characters.

Try this:
[code]<?php
if (strlen($USR) < 5) // the "!" is the "not operator" -- don't use it here
{
    echo '<font color="blue" size="4">Error:</font><font color="blue" size="3"><i> Your username can not be less than 5 characters</i></font>';
}
else
{
?>[/code]

Ken
Link to comment
Share on other sites

ohh!, username cant be less than 5 characters, and no more than 18 characters

but that isnt the problem, that works ( the less than 5 char one )

the problem is, that I cant get multiple IF's to work with it

E.G

I want it to check if username is to long/short
( Display the error for long/short )

then check if password's to long/short
( Display the error for long/short )

then check if confirm password not equal to password
if so ( Display the error for passwords not matching )

for now, thats what i'll start with

Do you know what I mean?
Link to comment
Share on other sites

Could you  not check this all in one and have one generic warning to say something like "there is an error with your chosen username and/or password, please check and try again".

You could then do something like this:

[code]
<?php

if (strlen($_POST['user']) > 4 && strlen($_POST['user']) < 19 && strlen($_POST['password']) > ? && strlen($_POST['password']) < ?) {

// enetered details are ok, process

} else {

// entered details are NOT ok, show warning

}

?>

[/code]

You will need to replace the ?'s to determine password length.
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.