4 Replies - 816 Views - Last Post: 01 June 2009 - 10:47 PM Rate Topic: -----

#1 kunkka   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 99
  • Joined: 15-May 09

i cant direct to the home page with welcoming the username which logge

Posted 01 June 2009 - 09:40 AM

how can i put the username which user logged in

i have check if the user is rite the page will direct to the home.php. but in home.php i want to show the username in the page.

how can i do that
Is This A Good Question/Topic? 0
  • +

Replies To: i cant direct to the home page with welcoming the username which logge

#2 CTphpnwb   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3798
  • View blog
  • Posts: 13,755
  • Joined: 08-August 08

Re: i cant direct to the home page with welcoming the username which logge

Posted 01 June 2009 - 09:43 AM

How are we supposed to help you when we can't see your code? How can we possibly say what you're doing worng?
Was This Post Helpful? 0
  • +
  • -

#3 kunkka   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 99
  • Joined: 15-May 09

Re: i cant direct to the home page with welcoming the username which logge

Posted 01 June 2009 - 09:50 AM

This is my login page

<?php

	require($_SERVER["DOCUMENT_ROOT"]."/config/db_config.php");
	$connection= @mysql_connect($db_host,$db_user,$db_password) or die("Error Connecting");
	mysql_select_db($db_name,$connection);
	
	if (isset($_POST["username"]) && isset($_POST["password"]))
		{
			$username = mysql_real_escape_string($_POST["username"]);
			$password = mysql_real_escape_string($_POST["password"]);
			
			$query = "SELECT * FROM login WHERE Username='$username' and Password='$password'";
			
			echo ($query);
			
			
				$results = mysql_query($query);if(mysql_num_rows($results) == 1) 
			{
				$_SESSION['username'] = $_REQUEST['username'];
				echo '<script type=""text/javascript"">location.replace("home.php")</script>';
			} 
			
			else 
			{
				
				echo '<script type=""text/javascript""> alert("Access Denied! Incorrect Username or Password") </script>'; 			
				
			}
		}
?>


<head>
<style type="text/css" media="all">
@import "css/stylemaster.css";.style1 {font-size: 10px}
.style3 {font-size: 10px; font-weight: bold; }
.style4 {color: #FFFFFF}
body {
	background-color: #FFFFFF;
}
</style>
</head>


<body>   

<div id="page-container"> 
 		<div id="header"><h1>&nbsp;</h1>
   </div>
		<div id="main-nav">Main Nav</div>
		
		<div id="sidebar-a">  
	  
<form id="form1" name="form1" method="post" action="home.php">
			
		  <h3 class="style1">&gt;&gt; Login </h3>
		  <pre>User Type :  <select name="usertype" size="1" id="usertype">					   <option selected="selected">Student</option>					   <option>Lectuerer</option>					   <option>Administrator</option>					   </select>				 
		  </pre>
		  <pre>User Name:   <input name="username" type="text" id="username" value="" size="12px" />		   
		  </pre>
		  <pre>Password :&nbsp;  <input type="password" name="password" id="password" size="12px"/>
		  </pre>
		  <pre>			 <input type="submit" name="Login" value="Submit" />		   
		  </pre>
<p>Not a member yet?<br>
			<a href="register.php">Register Now!</a></p>
		  <p>&nbsp; </p>
</form>
</div>

	 </body> 




this is my home.php


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

<style type="text/css" media="all">
@import "css/stylemaster.css";.style1 {font-size: 10px}
.style3 {font-size: 10px; font-weight: bold; }
.style4 {color: #FFFFFF}
body {
	background-color: #FFFFFF;
}
</style>
<title>Online Examination</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /></head>

<body>
 <div id="page-container"> 
 		<div id="header"><h1>&nbsp;</h1>
   </div>
		<div id="main-nav">Main Nav</div>
   <div id="sidebar-a" >
   
 <font class="ws8" color="#FF9900" face="Tahoma"></font>
	
	<form action="home.php" method="post">
		Welcome <?php echo ((isset($_SESSION['username']) ?$_SESSION['username'])) ?>
	</form>
		 
		  </div>
		<div id="content">Content   Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nullam gravida enim ut risus. 
	Praesent sapien purus, ultrices a, varius ac, suscipit ut, enim. Maecenas in lectus. 
	Donec in sapien in nibh rutrum gravida. Sed ut mauris. Fusce malesuada enim vitae lacus 
	euismod vulputate. Nullam rhoncus mauris ac metus. Maecenas vulputate aliquam odio. 
	Duis scelerisque justo a pede. Nam augue lorem, semper at, porta eget, placerat eget, 
	purus. Suspendisse mattis nunc vestibulum ligula. In hac habitasse platea dictumst.  <h2>About</h2>
	<p><strong>Enlighten Designs</strong> is an Internet solutions provider that specialises in 
	   front and back end development. To view some of the web sites we have created view our 
	   portfolio.</p>
	<p>We are currently undergoing a 'face lift', so if you have any questions or would 
	   like more information about the services we provide please feel free to contact us.</p>
	
	<h2>Contact Us</h2>
	<p>Phone:   (07) 853 6060<br />
	Fax:	 (07) 853 6060<br />
	Email:   <a href="mailto:[email protected]">[email protected]</a><br />
	P.O Box: 14159, Hamilton, New Zealand</p>
	<p><a href="#">More contact information...</a></p>

</div>
		<div id="footer"><div id="altnav">
		<a href="#">About</a> - 
		<a href="#">Services</a> - 
		<a href="#">Portfolio</a> - 
		<a href="#">Contact Us</a> - 
		<a href="#">Terms of Trade</a>
	</div>
	Copyright &copy; Enlighten Designs
	<br/>
	Powered by <a href="http://www.enlightenhosting.com/">Enlighten Hosting</a> and
	<a href="http://www.vadmin.co.nz/">Vadmin 3.0 CMS</a>
</div>
		
 </div>
 
</body>
</html>




when the user logs in. i want to show that in my home page with the user's name
Was This Post Helpful? 0
  • +
  • -

#4 CTphpnwb   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3798
  • View blog
  • Posts: 13,755
  • Joined: 08-August 08

Re: i cant direct to the home page with welcoming the username which logge

Posted 01 June 2009 - 10:00 AM

First, your home.php page doesn't appear to have any php in it. Since it's just html, it is static. Sending information to it will do nothing.

Assuming you added the necessary php to it, you could send information to it using a session variable or using $_GET/$_REQUEST.
Was This Post Helpful? 0
  • +
  • -

#5 noorahmad   User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: i cant direct to the home page with welcoming the username which logge

Posted 01 June 2009 - 10:47 PM

try this:
in your PHP code i changed echo '<script type=""text/javascript"">location.replace("home.php")</script>'; to header("Location: home.php");
<?php

	require($_SERVER["DOCUMENT_ROOT"]."/config/db_config.php");
	$connection= @mysql_connect($db_host,$db_user,$db_password) or die("Error Connecting");
	mysql_select_db($db_name,$connection);
   
	if (isset($_POST["username"]) && isset($_POST["password"]))
		{
			$username = mysql_real_escape_string($_POST["username"]);
			$password = mysql_real_escape_string($_POST["password"]);
		   
			$query = "SELECT * FROM login WHERE Username='$username' and Password='$password'";
		   
			echo ($query);
		   
		   
				$results = mysql_query($query);if(mysql_num_rows($results) == 1)
			{
				$_SESSION['username'] = $_REQUEST['username'];
				header("Location: home.php");
			}
		   
			else
			{
			   
				echo '<script type=""text/javascript""> alert("Access Denied! Incorrect Username or Password") </script>';			
			   
			}
		}
?>



and change your home page to home.php

This post has been edited by noorahmad: 01 June 2009 - 10:50 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1