Danny Morales
Danny Morales

Reputation: 13

Sessions are not carrying through

I have an account.php page where the user has the ability to alter the account information saved on a mySQL database. When I click the link to it I get a message saying to "Go back and login before you visit this page!" My code is below.

pro.php (page directed to once logged in)

<?php

//STEP 1 Connect To Database
$connect = mysql_connect("Localhost","mlec2013_danny","8764963d");
if (!$connect)
{
die("MySQL could not connect!");
}

$DB = mysql_select_db('mlec2013_database');

if(!$DB)
{
die("MySQL could not select Database!");
}

//STEP 2 Declare Variables

$Name = $_POST['username'];
$Pass = $_POST['password'];
$Query = mysql_query("SELECT * FROM Users WHERE Username='$Name' AND Password='$Pass'");
$NumRows = mysql_num_rows($Query);
$_SESSION['username'] = $Name;
$_SESSION['password'] = $Pass;

//STEP 3 Check to See If User Entered All Of The Information

if(empty($_SESSION['username']) || empty($_SESSION['password']))
{
die("Go back and login before you visit this page!");
}

if($Name && $Pass == "")
{
die("Please enter in a name and password!");
}

if($Name == "")
{
die("Please enter your name!" . "</br>");
}

if($Pass == "")
{
die("Please enter a password!");
echo "</br>";
}

//STEP 4 Check Username And Password With The MySQL Database

if($NumRows != 0)
{
while($Row = mysql_fetch_assoc($Query))
{
$Database_Name = $Row['username'];
$Database_Pass = $Row['password'];
}
}
else
{
die("Incorrect Username or Password!");
}


//end of PHP scripting. Information displayed below is in the form of HTML, CSS, or Javascript.
?>

account.php

<?php
session_start()
?>

Upvotes: 0

Views: 43

Answers (1)

Piet van Dongen
Piet van Dongen

Reputation: 1639

Place session_start() at the top of pro.php page as well.

Upvotes: 1

Related Questions