surfacesicks Posted April 3, 2013 Share Posted April 3, 2013 Hi All masters, i am a newbie in PHP ( actualy a beginner/dummies in programing ) need help from u guys on how to pop out an error msg when login is unsuccesful, example "login failed please try again" below are my coding using PHP/CSS, hope someone can help me out Thanks A lot! <?php require_once('Connections/Otdb.php'); ?><?php// *** Validate request to login to this site.if (!isset($_SESSION)) { session_start();}$loginFormAction = $_SERVER['PHP_SELF'];if (isset($_GET['accesscheck'])) { $_SESSION['PrevUrl'] = $_GET['accesscheck'];}if (isset($_POST['username'])) { $loginUsername=$_POST['username']; $password=$_POST['password']; $MM_fldUserAuthorization = ""; $MM_redirectLoginSuccess = "form1.php"; $MM_redirectLoginFailed = "Login.php"; $MM_redirecttoReferrer = false; mysql_select_db($database_Otdb, $Otdb); $LoginRS__query=sprintf("SELECT username, password FROM user WHERE username='%s' AND password='%s'", get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password)); $LoginRS = mysql_query($LoginRS__query, $Otdb) or die(mysql_error()); $loginFoundUser = mysql_num_rows($LoginRS); if ($loginFoundUser) { $loginStrGroup = ""; //declare two session variables and assign them $_SESSION['MM_Username'] = $loginUsername; $_SESSION['MM_UserGroup'] = $loginStrGroup; if (isset($_SESSION['PrevUrl']) && false) { $MM_redirectLoginSuccess = $_SESSION['PrevUrl']; } header("Location: " . $MM_redirectLoginSuccess ); } else { header("Location: ". $MM_redirectLoginFailed ); }}?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><title>Login PHP</title><style type="text/css"><!--.style1 { font-size: x-large; font-weight: bold; font-style: italic; color: #FF0000;}.style2 { font-size: large; font-style: italic; font-weight: bold;}--></style></head><body><div align="center"><form ACTION="<?php echo $loginFormAction; ?>" name="form1" method="POST"> <div id="logo" style="width:100%; height:100px; background:url(file:///C|/Users/sanmina/Desktop/www/images/bannerLogo.png) no-repeat left top #9e0b0f;"></div> <p><img src="bannerLogo.png" width="500" height="68"></p> <table width="396" height="111" border="0" cellpadding="3" cellspacing="0"><tr><td width="100"><span class="style2">Username:</span></td><td><input name="username" type="text" id="username"></td></tr><tr><td width="100"><span class="style2">Password:</span></td><td><input name="password" type="password" id="password"></td></tr><tr><td width="100"> </td><td><input type="submit" name="Submit" value="Submit"></td></tr></table> <p> </p> <p class="style1">Online Overtime Planning System </p> <p> </p> <div id="div" style="width:100%; height:100px; background:url(file:///C|/Users/sanmina/Desktop/www/images/bannerLogo.png) no-repeat left top #9e0b0f;"></div> <p> </p></form></div></body></html> Link to comment Share on other sites More sharing options...
surfacesicks Posted April 5, 2013 Author Share Posted April 5, 2013 Helooo...not getting any help here...helloo..am i at the wrong forum? Link to comment Share on other sites More sharing options...
Ingolme Posted April 5, 2013 Share Posted April 5, 2013 Well, it seems to be fine, generally. When the login fails, this line takes care of that: else {header("Location: ". $MM_redirectLoginFailed );} Be sure to put an exit; statement right after sending the header so that if there are delays the page won't show the rest of the content. There's more than one way to show a message upon failure. The "login failed" page you're redirecting to could be an HTML page with the message in it and a timed meta redirect. <meta http-equiv="refresh" content="5;login.php"> 1 Link to comment Share on other sites More sharing options...
surfacesicks Posted April 5, 2013 Author Share Posted April 5, 2013 At last..thanks for your advice 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