supergrame Posted October 28, 2009 Share Posted October 28, 2009 Hi guys. just so you know im not asking for someone to do this for me I just need to be pointed in the right direction... here is my problem. I have index.php in that file i have included login.php witch has the php and the html to produce the login form and the php to cheak the database. now what i want... How can i produce errors like username doesnot exist or password incorect stuff like that but I want that to be on the index.php page with out it going to a new page and displaying wrong username/password. I just need to know what to look for so i can google it and do my own research as to how this works. Thnak you Quote Link to comment https://forums.phpfreaks.com/topic/179400-display-error-above-the-login-forum-help/ Share on other sites More sharing options...
MadTechie Posted October 28, 2009 Share Posted October 28, 2009 Personally i would have the PHP file include the HTML file, but at the start i would check to see if the form was posted, if it was then run the checks.. that way you can just echo the messages here's a very rough example (untested) <?php $error =""; if(isset($_POST['Send'])) { //check $_POST['username'] if($_POST['username'] == "bob") { header("Location: profile.php"); //redirect to profile.php exit(); }else{ $error ="Unknown user"; } } ?> <!--HTML stuff starts here--> <?php if(!empty($error)){ ?> <div clas="error"> <?php echo $error; ?> </div> <?php } ?><!--more HTML stuff here--> EDIT: oops noticed a few typos Quote Link to comment https://forums.phpfreaks.com/topic/179400-display-error-above-the-login-forum-help/#findComment-946626 Share on other sites More sharing options...
supergrame Posted October 29, 2009 Author Share Posted October 29, 2009 hey thanks for that im trying to get my head around it. its so confusing. i guess time and practices is all i need Quote Link to comment https://forums.phpfreaks.com/topic/179400-display-error-above-the-login-forum-help/#findComment-946706 Share on other sites More sharing options...
MadTechie Posted October 29, 2009 Share Posted October 29, 2009 okay here's a sample you can try, I cleaned it up a little, and added some more comments and it works (username='bob') <?php //init error message $error =""; //Check to see if the form as been posted if(isset($_POST['Send'])) { //Check username if($_POST['username'] == "bob") { header("Location: profile.php"); //redirect to profile.php exit(); }else{ //Username is incorrect //assign message for error $error ="Unknown user"; } } ?> Please Login:~ <!-- form --> <form action="" method="POST"> <input type="text" name="username" /> <input type="submit" name="Send" value="Login" /> </form> Blar Blar Blar Blar Blar <br /> <?php if(!empty($error)){ ?> <div clas="error"> <B><?php echo $error; ?></B> </div> <?php } ?> <br /> la la la la la la la la la la la <!--more HTML stuff here--> Quote Link to comment https://forums.phpfreaks.com/topic/179400-display-error-above-the-login-forum-help/#findComment-946714 Share on other sites More sharing options...
supergrame Posted October 29, 2009 Author Share Posted October 29, 2009 ahh thank you that is much easier for me to work with im still in the beginner stage.. I think i jumped in over my head, hehe thank you I will post here again in an hour or so and let you know how i got on. Quote Link to comment https://forums.phpfreaks.com/topic/179400-display-error-above-the-login-forum-help/#findComment-946727 Share on other sites More sharing options...
supergrame Posted October 29, 2009 Author Share Posted October 29, 2009 were this line is if($_POST['username'] == "bob") can i just add a database query right in there Quote Link to comment https://forums.phpfreaks.com/topic/179400-display-error-above-the-login-forum-help/#findComment-946845 Share on other sites More sharing options...
lakshmiyb Posted October 29, 2009 Share Posted October 29, 2009 hi it is working well, but ihave the login form as lightbox, it is not working there here is my code for lightbox with error display code <?php if(isset( $_SESSION['Email'])) { echo "<a href='signout.php' class='style1'><img src='images/SIGNOUT-LOGO.jpg' alt='SIGNIN' width='18' height='21' border='0' /> </a>";} else { echo "<div id='filter'></div> <div id='box'> <span id='boxtitle'></span> <?php if(!empty($error)){ ?> <B><?php echo $error; ?></B> <?php }?> <form method='POST' action='#' target='_parent'> <table width='98%' border='0' cellspacing='0'> <tr> <td width='47%'> <span class='style1'>Email ID </span></td> <td width='53%'><input name='Email' type='text' size='11' /></td> </tr> <tr> <td> <span class='style1'>Password</span></td> <td><input name='Password' type='password' size='13' /></td> </tr> <tr> <td> <table width='100' border='0' cellspacing='0' cellpadding='0'> <tr> <td width='10'> </td> <td><a href='registerpage.php'><span class='style1'>Register</span></a></td> </tr> </table></td> <td><input type='image' name='Submit' src='images/login.jpg' id=login_button/> <input type='button' name='cancel' value='Cancel' onclick='closebox()' /></td> </tr> <tr> <td colspan='2' align='center'> <a href='forgotpassword.php'><span class='style1'>Forgot Password </span></a></td> </tr> </table></form> </div> <a href='#' onClick='openbox()'><img src='images/SIGNIN-LOGO.gif' alt='SIGNIN' width='23' height='26' border='0' /></a>"; } ?> please help me Quote Link to comment https://forums.phpfreaks.com/topic/179400-display-error-above-the-login-forum-help/#findComment-946917 Share on other sites More sharing options...
MadTechie Posted October 29, 2009 Share Posted October 29, 2009 @lakshmiyb: please create your own thread, no hi-jacking of posts here Quote Link to comment https://forums.phpfreaks.com/topic/179400-display-error-above-the-login-forum-help/#findComment-946975 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.