I am trying to assign a value from a query result to a session but it isn't working..
Session username below, i am registering the session username which is the users email
$_SESSION['myusername'] = $myusername;
check login Here i am trying to get the customer name from the same table were the email is stored and save it in the "name" session
$_SESSION['name'] = $row['name'];
Logged success here i am trying to fetch the user's name
echo "Welcome ". $_SESSION['name'];
check login page*
<?php
ob_start();
$host="localhost"; // Host name
$username="xx"; // Mysql username
$password="xx"; // Mysql password
$db_name="xx"; // Database name
$tbl_name="customer"; // Table name
$db_usercol="email"; // Field containing username
$db_passcol="password"; // Field containing password
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// username and password sent from form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql="SELECT * FROM $tbl_name WHERE $db_usercol='$myusername' and $db_passcol='$mypassword'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){
// Register $myusername, $mypassword and redirect to file "profile.php"
session_register("myusername");
session_register("mypassword");
$_SESSION['myusername'] = $myusername;
$_SESSION['name'] = $row['name'];
header("location:profile.php");
}
else {
echo "Wrong Username or Password";
}
ob_end_flush();
?>
on successful login*
<?
// Check if session is not registered , redirect back to main page.
// Put this code in first line of web page.
session_start();
if(isset($_SESSION[$myusername])){
header("location:members.php");
}
else
include("header.php");
?>
<body id="profile">
<div id="wholewrap">
<div id="bodywrap">
<div id="content">
<h1>Your Profile</h1>
<?php
echo "Welcome ". $_SESSION['myusername'];
echo "Welcome ". $_SESSION['name'];
?>
</div> <!-- content #end -->
<div id="sidebar">
Lorem Ipsum
</div> <!-- sidebar #end -->
</div> <!-- bodywrap #end -->
</div> <!-- wholewrap #end -->
<?php include("footer.php"); ?>
The result is
I only get the username but not the name of the user, which is a field in the same table named name

session_start()on both pages?