kafia Posted December 15, 2009 Report Share Posted December 15, 2009 Hellow every one i have the following simple login code. is there any way to catch all the error messeges into one resulting array .and after print that array variable to any place where we want on the page <?php include('config.php'); if(loggedin()) { header("location:welcome.php"); exit(); } if(isset($_POST['login'])) { $name=$_POST['name']; $pass=$_POST['pass']; $rememberme=$_POST['rememberme']; // fields validation if(empty($name )&& empty($pass)) { die("Please enter your user name and password!"); } if(empty($name)) { die("Please enter your user name !"); } if(empty($pass)) { die("Please enter your password!"); } // getting data from the data base else $query=mysql_query("SELECT * FROM user WHERE username='$name'"); $numrow=mysql_num_rows($query); if($numrow !=0) { while($row=mysql_fetch_array($query)) { $dbname=$row['username']; $dbpass=$row['password']; } // check to see if they match if($name==$dbname && md5($pass)==$dbpass) $loginok=true; else $loginok=false; if ($loginok==true) { if($rememberme==on) setcookie("name" , $name , time() + 7200); else $_SESSION['name']=$name; header("location:welcome.php"); exit(); } else echo "sorry Incorrect password"; } else echo" Sory User does't Exist"; }?><form action="login.php" method="post">User name: <br/><input type="text" name="name"><p>Password: <br/><input type="password" name="pass"><p><input type="checkbox" name="rememberme"> Remember Me!<br/><p><input type="submit" name="login" value="Log In"><a href ="register.php">back to register</a></form> Link to comment Share on other sites More sharing options...
justsomeguy Posted December 15, 2009 Report Share Posted December 15, 2009 You can use an array to store and display errors, what problems are you having? Have you looked through the array tutorial section? Link to comment Share on other sites More sharing options...
kafia Posted December 15, 2009 Author Report Share Posted December 15, 2009 thanks for reply i use the array but it not working spose if i enter the worng password the script echo "sorry incorrect password" next if i enter wrong user name script echo"sory that user does not exist " i want the put all these messeges into one variable and after i want the print it on my wanted place in the form or i want tho print the error messege in front of the respect input box Link to comment Share on other sites More sharing options...
justsomeguy Posted December 15, 2009 Report Share Posted December 15, 2009 Show the code where you're using the array. You just need to initialize it as an empty array, then add each message you want to it. You can always check the length of the array to see if any errors happened. At the end you can loop through it to display each message. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now