Mythic Fr0st Posted December 2, 2006 Share Posted December 2, 2006 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 outCode( 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><?phpif (!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 Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted December 2, 2006 Share Posted December 2, 2006 You're taking the string length of a literal -- the string "user", which is always 4.What are you really wanting to do here?Ken Quote Link to comment Share on other sites More sharing options...
Mythic Fr0st Posted December 2, 2006 Author Share Posted December 2, 2006 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 soI 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] Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted December 2, 2006 Share Posted December 2, 2006 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]<?phpif (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 Quote Link to comment Share on other sites More sharing options...
Mythic Fr0st Posted December 2, 2006 Author Share Posted December 2, 2006 Lol, I swore I tried it without ! lol, thanks alot, you fixed it !!! O_O Quote Link to comment Share on other sites More sharing options...
chiprivers Posted December 2, 2006 Share Posted December 2, 2006 I replied on your new post but it has disappeared!Could you explain in literal terms the rules for your username, we can then look at the best way to check it. Quote Link to comment Share on other sites More sharing options...
Mythic Fr0st Posted December 2, 2006 Author Share Posted December 2, 2006 What do you mean literal rules? ( Sorry im a noob )do you have msn/icq/aim/YIM Quote Link to comment Share on other sites More sharing options...
chiprivers Posted December 2, 2006 Share Posted December 2, 2006 Can you explain what restriction exactly you want to impose on the username, ie minimum and maximum length. Quote Link to comment Share on other sites More sharing options...
Mythic Fr0st Posted December 2, 2006 Author Share Posted December 2, 2006 ohh!, username cant be less than 5 characters, and no more than 18 charactersbut 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 itE.GI 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 passwordif so ( Display the error for passwords not matching )for now, thats what i'll start withDo you know what I mean? Quote Link to comment Share on other sites More sharing options...
chiprivers Posted December 2, 2006 Share Posted December 2, 2006 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]<?phpif (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. Quote Link to comment Share on other sites More sharing options...
Mythic Fr0st Posted December 2, 2006 Author Share Posted December 2, 2006 erm, I thought of that, but im too fussy, it has to be preciseHOWEVER, I completely stripped all the confusing stuff back, and found a easy way to do it Lolzsoo easy, its :-[ :-[Thanks for your help though!!!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.