Jump to content

Display error above the login forum help!


supergrame

Recommended Posts

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

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

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-->

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.