Three files this time. The sessions is not done in the log in page and I do not pay any attention to the menu so if you want that to work you should be able to incorporate it. I would put it on the last page.
Your main code:
Code:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" >
<style>
#signin{
display:none;
}
body {
//background-color: #333;
}
#container{
width: 1014px;
}
#loginbutton{
//float:right;
}
#main{
clear:both;
}
#here, #hereagain{
display:none;
}
</style>
<link href="modal.css" rel="stylesheet" type="text/css">
<script type='text/javascript' src='javascript/jquery.js'></script>
<script type="text/javascript">
$(document).ready(function(){
$("#loginbutton").click(function(){
$("#signin").css("display", "block");
$("#here").css("display", "none");
document.getElementById("username").focus();
});
$("#away").click(function(){
var username = $("#username").val();
var password = $("#password").val();
$.post("login.php", { name: username, pass: password },
function(data){
$("#here").css("display", "block");
$("#here").html(data);
});
$("#signin").css("display", "none");
});
});
</script>
</head>
<body>
<div id="container">
<button id="loginbutton">Login/Register</button>Bill Clinton
<div id="main">
<table width="1014" border="1" align="center">
<tr>
<td width="109" height="54"> </td>
<td width="780"><div align="center" class="carlogos"></div></td>
<td width="103"> </td>
</tr>
<tr>
<td height="74"></td>
<td><div class="site_logo"></div></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> <div id="nav-menu">
<ul>
<li><a href="#">Home</a></li>
<li id="sellcarlist"><a href="#">Sell Cars</a></li>
<li><a href="#">Services</a></li>
<li><a href="#">About Us</a></li>
<li><a href="#">Contact Us</a></li>
</ul>
</div> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
</div>
</div>
<div id="signin">
Username:<input name="username" type="text" id="username"><br>
Password:<input name="password" type="password" id="password"><br>
<button id="away">Login</button>
</div>
<div id="here">Name or password</div>
<div id="hereagain">Name or password incorrect<br>Try again</div>
</body>
</html>
This calls the login.php script:
PHP Code:
<?php
session_start();
if(isset($_SESSION['uname']))
unset($_SESSION['uname']);
//include_once('conndb1.php');
require ('./inc/DB_connect.php');
$username = mysql_real_escape_string($_POST["name"]);
$password = mysql_real_escape_string(md5($_POST["pass"]));
$sql =("SELECT rsn from clan_members where password='$password'");
$res = mysql_query($sql)or die(mysql_error());
$row = mysql_fetch_row($res);
if($row[0] == $username)
{
$_SESSION["uname"] = $username;
echo 'Logged In <button id="continue" onclick="window.location.href = \'continue.php\';">Continue</button>';
}
if($row[0] != $username)
{
echo 'Name or password incorrect<br>Try again';
}
?>
The final page is the continue.php:
PHP Code:
<?php
session_start();
echo "I am the continue page<br />";
echo $_SESSION['uname'];
?>
This page shows that the sessions has been set. You need to do some checking on your inputs and make sure they have content and that it's the correct content because leaving things blank will work as a login.