maxic0 Posted April 13, 2007 Share Posted April 13, 2007 Hi, im creating a simple login script and i dont have a problem yet but im wondering if there is a way that i can improve this bit of code, this is what i have for validating the fields... <?php if (!isset($username) { echo "Username is a required field. <BR/> Please go <A HREF='register.php'>back</A> and fill it in."; } ?> I have four of these bits of code for validating the username, password, confirm password and email. If there a way that i could use one if statement to validate all the fields then if one or more fields are left blank, it will say that they are required fields and say what ones they have missed out? Thanks. Quote Link to comment Share on other sites More sharing options...
taith Posted April 13, 2007 Share Posted April 13, 2007 no... each one needs to be validated seperatly... if(empty($_POST[username]) echo "Username is a required field. <BR/> Please go <A HREF='register.php'>back</A> and fill it in."; elseif(empty($_POST[password]) echo "Password is a required field. <BR/> Please go <A HREF='register.php'>back</A> and fill it in."; elseif(empty($_POST[email]) echo "Email is a required field. <BR/> Please go <A HREF='register.php'>back</A> and fill it in."; and so on :-) Quote Link to comment Share on other sites More sharing options...
maxic0 Posted April 13, 2007 Author Share Posted April 13, 2007 Ok cheers dude! Quote Link to comment Share on other sites More sharing options...
taith Posted April 13, 2007 Share Posted April 13, 2007 personally... i prefer the less specific ones... $username=addslashes(strip_tags($_POST[username])); $password=md5($_POST[username]); $query=mysql_query("SELECT * FROM `accounts` WHERE `username`='$username' AND `password`='$password' LIMIT 1"); $row=mysql_fetch_array($query); if(empty($row)){ $_SESSION[error]='Invalid username/password'; redirect(); }else{ $_SESSION[user]=$row; redirect(); } Quote Link to comment Share on other sites More sharing options...
maxic0 Posted April 13, 2007 Author Share Posted April 13, 2007 Looks complicated lol, thanks! 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.