Hi, everyone. I’m having a problem storing session data. I have three pages: a login page, a registration page, and a frame that’s meant to be in the corner of all of the pages. The registration page creates mysql username, password, first name, last name and primary key variables each time someone registers. The login page takes a username and password provided by the user, checks them against the mysql data, and stores the corresponding mysql first and last name variables in a session. The problem I am having is that these variables do not seem to be passed on to the corner frame.
Registration code:
[php]<?php
if($_POST["firstname"]!=null)
{
if($_POST["password"]==$_POST["password2"])
{
$databaseConnection = mysql_connect ("localhost", "root");
mysql_select_db("users", $databaseConnection);
mysql_query("INSERT INTO usernamesandpasswords (Username, Password, FirstName, LastName)
VALUES ('$_REQUEST[username]', '$_REQUEST[password]', '$_REQUEST[firstname]', '$_REQUEST[lastname]')");
echo 'Thank you for your registration! <a href= login.php >Please login here.</a>';
}
else
{?>
Registration:
First name:
Last name:
Email (this will be your username):
Your passswords did not match.
Password:
Confirm Password:
Registration:
First name:
Last name:
Email (this will be your username):
Password:
Confirm Password:
Login code:
[php]<?php session_start();
if ($_REQUEST['username']!=null)
{
$databaseConnection = mysql_connect ("localhost", "root");
mysql_select_db("users", $databaseConnection);
$sql = "SELECT * FROM usernamesandpasswords WHERE Username='$_REQUEST[username]'";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
if ($row['Password'] = $_REQUEST['password'])
{
$_SESSION[username] = $_REQUEST[username];
$_SESSION[name] = $row[FirstName]." ".$row[LastName];
if ($_SESSION[name] == " ")
{?>
Your username or password was incorrect. Please reload this page by clicking here.
<?php }
else
{
echo "Hi, ".$_SESSION[name]."!";
}
}
else
{?>
Your username or password was incorrect. Please reload this page by clicking here.
<?php }
}
else
{?>
Username:
Password:
Frame code:
[php]<?php
if (!isset($_SESSION['name']))
{
$session = false;
}
else
{
$session = true;
}
?>
<?phpif ($session)
{
echo "Hello, ".$_SESSION['name'].$_SESSION['username']."!";
}
else
{
echo "Hello, guest! <a href='login.php' target='main'>Login here</a> or <a href='registration.php' target='main'>sign up here</a>!";
}
?>
[/php]Thank you all in advance!