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. Link to comment https://forums.phpfreaks.com/topic/46910-simple-login-script/ 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 :-) Link to comment https://forums.phpfreaks.com/topic/46910-simple-login-script/#findComment-228713 Share on other sites More sharing options...
maxic0 Posted April 13, 2007 Author Share Posted April 13, 2007 Ok cheers dude! Link to comment https://forums.phpfreaks.com/topic/46910-simple-login-script/#findComment-228714 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(); } Link to comment https://forums.phpfreaks.com/topic/46910-simple-login-script/#findComment-228716 Share on other sites More sharing options...
maxic0 Posted April 13, 2007 Author Share Posted April 13, 2007 Looks complicated lol, thanks! Link to comment https://forums.phpfreaks.com/topic/46910-simple-login-script/#findComment-228745 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.