By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,278 Members | 1,342 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,278 IT Pros & Developers. It's quick & easy.

after include login.php in homepage, the print message cant display in homepage

100+
P: 127
Below is my login function, it can work well, but after i include it at my homepage, the print message is in the login page...
What should it do to make the print message invalid username or password and please enter you enter both username and password display in homepage, please help me...
[PHP]<?php
ob_start();
session_start();
?>

<html>
<head>
<style type="text/css">
/* clsForgotPassword */
a.clsForgotPassword:link {color: #0000FF}
a.clsForgotPassword:visited {color: #0000FF}
a.clsForgotPassword:hover {color: #000099}
a.clsForgotPassword:active {color: #000099}
a.clsRegister:link {color: #0000FF}
a.clsRegister:visited {color: #0000FF}
a.clsRegister:hover {color: #000099}
a.clsRegister:active {color: #000099}
</style>
</head>

<?
$conn=mysql_connect("localhost", "root", "") or die (mysql_error());
mysql_select_db("ums e-job portal", $conn) or die(mysql_error());

$_SESSION['loggedin'] = 0;

$result = mysql_query("SELECT * FROM alumni WHERE username='{$_POST['username']}' AND password='{$_POST['password']}'")
or die(mysql_error());

$row = mysql_fetch_array( $result ); //okay

if (isset($_POST['submit'])){

if ((!empty ($_POST['username']))&&(!empty($_POST['password'])) ){//no forgot field

if($row['username'] == ''){
print '<p><strong>Invalid username or password.</strong><br />Please try again.</p>';

}else{

$_SESSION['loggedin'] = 1;
$_SESSION['loggedin'] = time();
$_SESSION['username'] = $row['username'];
$_SESSION['company_ID'] = $row['company_ID'];

header ('Location: welcome.php');
exit();
}

}else{//Forgot a field.
print'<p><strong>Please make sure you enter both <br />username and password!</strong></p>';
}

}
?>[/PHP]

[HTML]<form action="alumniLogin.php" method="POST">
<TABLE width="166" cellPadding=0 cellSpacing=0 bgcolor=#8870AB style="BORDER-RIGHT: #9B77CB 1px double; PADDING-RIGHT: 0px; BORDER-TOP: #9B77CB 1px double; PADDING-LEFT: 0px; FONT-WEIGHT: bold; FONT-SIZE: 10px; BACKGROUND-IMAGE: PADDING-BOTTOM: 0px; MARGIN: 0px; VERTICAL-ALIGN: top; BORDER-LEFT: #9B77CB 1px double; WIDTH: 140px; COLOR: #000000; PADDING-TOP: 0px; BORDER-BOTTOM: #9B77CB 1px double; FONT-STYLE: normal; FONT-FAMILY: Verdana; TEXT-DECORATION: none" >
<tr align="center" bgcolor="#BA5179">
<td width> <center>
<font color="#FFFFFF" size="3" face="Verdana"><strong>ALUMNI LOGIN</strong></font> </center>
</td>
</tr>
<tr bgcolor="#FFD7E6">
<td width><font size="2" face="Verdana"><strong>&nbsp;&nbsp;&nbsp;Username</strong></font></td>
</tr>
<tr bgcolor="#FFD7E6">
<td width><font size="2" face="Verdana">&nbsp;
<input type="text" name="username" size="24">&nbsp;
</font></td>
</tr>
<tr bgcolor="#FFD7E6">
<td><font size="2" face="Verdana"><strong>&nbsp;&nbsp;&nbsp;Password</strong></font></td>
</tr>
<tr bgcolor="#FFD7E6">
<td><font size="2" face="Verdana">&nbsp;
<input type="password" name="password" size="24">&nbsp;
</font></td>
</tr>
<tr bgcolor="#FFD7E6"><td colspan="2"><font size="2" face="Verdana">&nbsp;
<input type="submit" name="submit" value="Login">
</font></td>
</tr>
<tr bgcolor="#FFD7E6">
<td colspan="2">&nbsp;&nbsp;&nbsp;<a href="forgotPassword.php" class="clsForgotPassword"><font size="1.8" face="Verdana">Forgot
password?</font></a></td>
</tr>
<tr bgcolor="#FFD7E6">
<td colspan="2"><font size="1.8" face="Verdana">&nbsp;&nbsp;&nbsp;Not Register Yet? <br>&nbsp;&nbsp;&nbsp;<a href="alumniRegister.php" class="clsRegister">Register
Now!</a></font></td>
</tr>
<tr bgcolor="#FFD7E6">
<td colspan>&nbsp;</td>
</tr>
</table>
</form>[/HTML]
Mar 2 '07 #1
Share this Question
Share on Google+
3 Replies


ronverdonk
Expert 2.5K+
P: 4,258
Pass the error indicator to the home page. You can do that by invoking the home page (using the header() function) and passing the error indicator in the url.

Something like [php]header('Location: homepage.php?showerror=1');[/php]
Your home page then must check for the error trigger set in the $_GET array and print the message, like:
[php]
if (isset($_GET['showerror']) AND $_GET['showerror'] == 1) {
print'<p><strong>Please make sure you enter both <br />username and password!</strong></p>';
}[/php]

Ronald :cool:
Mar 2 '07 #2

100+
P: 127
Pass the error indicator to the home page. You can do that by invoking the home page (using the header() function) and passing the error indicator in the url.

Something like [php]header('Location: homepage.php?showerror=1');[/php]
Your home page then must check for the error trigger set in the $_GET array and print the message, like:
[php]
if (isset($_GET['showerror']) AND $_GET['showerror'] == 1) {
print'<p><strong>Please make sure you enter both <br />username and password!</strong></p>';
}[/php]

Ronald :cool:
Thanks... It work for me...
But if i want the pop up window for the users when they don't enter the username or password or they insert invalid username or password, is it need to use javascript??
how to code it??? Thanks.. :)
Mar 2 '07 #3

ronverdonk
Expert 2.5K+
P: 4,258
Your question (and thread title) was to display it at the home page. Are you telling me that that was wrong and now you want it as a popup screen?

If so, start developing some of the JS code and we will have a look at it when you envounter errors.

Ronald :cool:
Mar 2 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.