Kind of a PHP newbie and trying to display a username (which is an email address) after login, but having problems getting the PHP to actually spit anything out.
I have a login index page that directs to a page with this PHP code:
Code: Select all
//DB variables taken out of this example
// 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['email'];
$mypassword=$_POST['password'];
// 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 email='$myusername' and password='$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 "/members/tools.php"
$_SESSION['email'] = $myusername;
$_SESSION['password'] = $mypassword;
header( "Location: /members/tools.php" );
}
else
{
echo "Wrong Username or Password";
exit();
}
?>Code: Select all
<?
// Check if session is not registered , redirect back to main page.
// Put this code in first line of web page.
session_start();
if(!session_is_registered(myusername)){
header("location:/members/");
}
?>
<html>
<head>
</head>
<body>
<p>Login Successful! Welcome <?php echo $_SESSION['email']; ?></p>
<p>Select an option below to get started...</p>
<ul>
<li><a href="/members/contactlist.php">Team Member Contact List</a></li>
<li><a href="/members/traininglog.php">Training Log</a></li>
<li><a href="/members/logout.php">Logout of Member Tools</a></li>
</ul>
</body>
</html>Andy