0

Can anyone please tell me why this session variable isn't being set? When the login details are correct the offers page is re-directing users back to the index as though the session variable isn't set.

<?php
session_start();

$username = $_POST['username'];
$password = $_POST['password'];

mysql_connect("localhost", "******", "******") or die("Could not connect.");
mysql_select_db("*******") or die("Could not find database.");

if(($username=='')||($password==''))
{
echo"<script type='text/javascript'>;
alert('Please check and re-enter details');
window.location = 'index.php';
</script>";
}
$qry="SELECT*FROM login WHERE username = '$username' and password = '$password'";
$result=mysql_query($qry);

if(mysql_num_rows($result)==0)
echo "<script type='text/javascript'>;
alert('The username you have entered does not exist in our database.  Please check ad re-enter details.');
window.location = 'index.php';
</script>";

if(mysql_num_rows($result)> 0)
{
$_SESSION['username'] = $username;
header('location: offers.php');
}
?>

offers.php code

<?php
if ($_SESSION["username"]=="") 
{
header ('Location: index.php');
}
?>
3

2 Answers 2

2

You need to put session_start(); at the top of your offers.php page.

Sign up to request clarification or add additional context in comments.

Comments

1

Try adding:

session_start();

to the top of offers.php

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.