PrinceOfDragons Posted August 11, 2009 Share Posted August 11, 2009 Is this an efficient way to check my form field? function checkUname() { global $uname; if($this->username == "") { echo "Username field is blank"; $this->myErrors++; } elseif($uname != $_POST['username'] && $_POST['Log-In'] == "Log-In"){ echo "Username does not exist"; $this->myErrors++; } elseif(strlen($this->username) < "5") { echo "Username is to short"; $this->myErrors++; } elseif(!eregi("^([0-9a-z])*$", $this->username)) { echo "Username is not Alphanumeric"; $this->myErrors++; } elseif($uname == true && $_SESSION['create'] == "Create Account"){ echo "Username Taken"; $this->myErrors++; Link to comment https://forums.phpfreaks.com/topic/169724-solved-help-please/ Share on other sites More sharing options...
oni-kun Posted August 11, 2009 Share Posted August 11, 2009 elseif(strlen($this->username) < 5 || strlen($this->username) > 15) Should be 5, "5" is a string. You should add a max amount of characters.. Link to comment https://forums.phpfreaks.com/topic/169724-solved-help-please/#findComment-895424 Share on other sites More sharing options...
The Little Guy Posted August 11, 2009 Share Posted August 11, 2009 if($this->username == "") { could be changed to if(empty($this->username)) { Link to comment https://forums.phpfreaks.com/topic/169724-solved-help-please/#findComment-895425 Share on other sites More sharing options...
oni-kun Posted August 11, 2009 Share Posted August 11, 2009 function checkUname() { global $uname; if(empty($this->username)) { echo "Username field is blank"; $this->myErrors++; } elseif($uname != $_POST['username'] && $_POST['Log-In'] == "Log-In"){ echo "Username does not exist"; $this->myErrors++; } elseif(strlen($this->username) < 5 || strlen($this->username) > 10) { echo "Username is to short"; $this->myErrors++; } elseif(!preg_match('/[^0-9a-zA-Z]/s', $this->username)) { echo "Username is not Alphanumeric"; $this->myErrors++; } elseif($uname == true && $_SESSION['create'] == "Create Account"){ echo "Username Taken"; $this->myErrors++; That should be better. Eregi is deprecated so it should be preg_match. Link to comment https://forums.phpfreaks.com/topic/169724-solved-help-please/#findComment-895434 Share on other sites More sharing options...
PrinceOfDragons Posted August 11, 2009 Author Share Posted August 11, 2009 Thanks for the help as I am new to php, I do not know the most efficent way to use the code but I can get it to do what I want . Link to comment https://forums.phpfreaks.com/topic/169724-solved-help-please/#findComment-895918 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.