View Single Post
Old 11-03-2012, 02:13 PM   PM User | #1
prash91
New Coder

 
Join Date: Oct 2012
Posts: 16
Thanks: 2
Thanked 0 Times in 0 Posts
prash91 is an unknown quantity at this point
Modal box login with session

Hi
I am trying to make login form through modal box, if user click login the box will appear including login form in it, if user goes through the login process the session will generate in index page with welcome message but i am confuse how to set session and recall it.
I have following details of my code

Register table, has 3 fields ID username Password
index.php
Code:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" /> 
<style>

#dialog{
	   display:none;
	   draggable: false, 
	   }
	   

</style>
<link href="modal.css" rel="stylesheet" type="text/css">
<style type="text/css">
body {
	background-color: #333;
}
</style>
</head>
 <body>
 
      <script type="text/javascript" src="autojs/jquery-1.8.2.min.js"></script> 
         <script type="text/javascript" src="autojs/jquery.bgiframe.js"></script>
      <script src="http://code.jquery.com/ui/1.9.1/jquery-ui.js"></script> 
         
         

<script type="text/javascript">
$( document).ready(function() {
        
   
		$('#loginbutton').click(function(){
			 $( "#dialog" ).dialog();
		});
		
		 });
		 

 </script> 
<div align="right" id="loginbutton"><a href="#">Login/Register</a></div>
<div id="container">
<table width="1014" border="1" align="center">
  <tr>
    <td width="109" height="54">&nbsp;</td>
    <td width="780"><div align="center" class="carlogos"></div></td>
    <td width="103">&nbsp;</td>
  </tr>
  <tr>
    <td height="74"></td>
    <td><div class="site_logo"></div></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</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>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>

</div>
<div id="dialog" title="Please LogIn">
   
  <script type="text/javascript">
	$("#submit").click(function(){
		var username = $("#username").val();
		var password = $("#password").val();
	
		$.ajax({
			
			type:"post",
			url:"login.php",
			data: "username=" + username + "&password=" + password,
			success: function(result){
				if(result=='0')
				{
					
					$("#dialog").dialog("close");
					//$("#loginbutton").html("welcome" + " " + username);	
					$("#loginbutton").html("welcome" + " " + sessName);
					
					 
				}else{
					$("#ack").html("incorrect user");
				}
			}
			});
		return false;

	});
</script>
   
   
   <form action="login.php" method="post" id="myform">
 Username:<input name="username" type="text" id="username"><br>
 Password:<input name="password" type="text" id="password"><br>
 <button id="submit">Login</button>
 </form>

<div id="ack">Click login</div>
</div>  
</body>
</html>
login.php
Code:
<?PHP
include_once('conndb1.php');


	$username = mysql_real_escape_string($_POST["username"]);
	$password = mysql_real_escape_string(md5($_POST["password"]));

	$sql =("SELECT * from register where username='$username' AND password='$password'");
	$res = mysql_query($sql)or die(mysql_error());
	if(mysql_num_rows($res)>0)
	{
		echo "0";
		session_start();
		 $_SESSION['uname']=$username;
	}


?>
at the moment i am displaying the username through jquery in logginbutton div tag but i want to display it through session.
prash91 is offline   Reply With Quote