Hi
I have a login page that sets session variables, and then displays a different home page depending on the usertype variable. However at the moment no matter what the usertype is set to in the database, the variable sets to "wedding" and displays as such.
The login page
<?php
session_start();
include_once('includes/connect.php');
if($_POST['submit'])
{
foreach ($_POST as $key => $val) {
$$key = mysql_real_escape_string($val);
}
//is the email already registered?
$user = mysql_query("SELECT * FROM `tbl_users` WHERE email_address='$username'"); //Added single quotes around $email
if(mysql_num_rows($user) > 0) //login name was found
{
//is the password correct
$checkpassword = mysql_query("SELECT * FROM `tbl_users` WHERE email_address='$username' and password=md5('$password')");
if(mysql_num_rows($checkpassword) > 0)//password is correct
{
$user_row = mysql_fetch_array($checkpassword);
$_SESSION['auth']="yes";
$_SESSION['logname'] = $user_row['forename'];
$_SESSION['usertype'] = $user_row['usertype'];
$_SESSION['user_id'] = $user_row['user_id'];
header("Location: index.php");
exit; //You should have an exit after a header('Location')
}
else //password is incorrect
{
$message="The username you entered exists, but you have not entered the correct password! Please try again.<br>";
}
}
else // username not found
{
$message = "The Login Name you entered does not exist! Please try again.<br>";
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Wedding Buddy | Making Your Big Day Special</title>
<link href="style/buddy.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="header">
<img src="images/bridegroom.jpg" />
</div>
<div id="maintext">
<form name="login" method="post" action="newlogin.php" onsubmit="return checkform()">
<p> </p>
<div align="center">
<table id="logincontainer">
<tr><td>
<table align="center">
<tr><td colspan="2"><h2>User Login</h2></td></tr>
<?php
if (isset($message))
{
echo "<tr><td style='color: red'
colspan='2' align='center'>$message <br /></td></tr>";
}
?>
<tr>
<td align="left">Username:</td><td align="left"><input name="username" type="text" size="30" /></td></tr>
<tr><td align="left">Password:</td><td align="left"><input name="password" type="password" size="30" /></td></tr>
<tr>
<td><img src="images/lock.png" /></td>
<td><input type="hidden" name="submit" id="hiddenField" value="1"/>
<input name="login2" type="submit" value="Login" class="button" /></td>
</tr>
</table>
</td></tr></table>
</div>
</form>
</div>
</body>
</html>
The home page code:
<?php
if(isset($_SESSION['usertype']))
{
if($_SESSION['usertype']="wedding")
{
include_once('includes/wedding_menu_inc.php');
}
else
{
include_once('includes/supplier_menu_inc.php');
}
}
else
{
include_once('includes/standard_menu_inc.php');
}
?>
<script type="text/javascript">
<!--
var MenuBar1 = new Spry.Widget.MenuBar("MenuBar1", {imgDown:"SpryAssets/SpryMenuBarDownHover.gif", imgRight:"SpryAssets/SpryMenuBarRightHover.gif"});
//-->
</script>
</div>
<div id="maintext"><p> </p><!-- InstanceBeginEditable name="maintext" -->
<?php
if(isset($_SESSION['usertype']))
{
if($_SESSION['usertype']="wedding")
{
echo('<h2><p>Hello '.$_SESSION['logname'].'</p></h2><p>Welcome back to Wedding Buddy, your online assistant to making <b>YOUR</b> big day special.</p>');
}
else
{
echo('<h2><p>Hello '.$_SESSION['logname'].'</p></h2><p>Welcome back to Wedding Buddy.
The FREE directory for those people preparing for their big day.</p>');
}
}
else
{
echo('Welcome to Wedding Buddy.');
}
?>
I can't see anything wrong with the code, but I must be missing something bt can't tell what, any help will be greatly appreciated.