Hi,
I am trying to use PHP sessions, but I’m having a bit of a problem.
I created an [B]INDEX.php
In this file I have the following
(a) session_start()
(b) database connection
(c) definition for ALL variables
(d) an input form for those attributes required upon registration — login, password, email, firstname, surname
The registration goes smoothly. From there, the user is re-directed to the login page ([B]LOGIN.php
This also works fine.
The problem is : the variables are not carried over (even though I specified [B]SESSION_START()
The user can log in, but the page does not show his data — such as “[B]Welcome, $firstname
I keep getting the error : [B]Variable “firstname” not defined
The same goes for each subsequent page………….from page to page, the variables are missing. They are not displayed. Only that annoying error message : “Variable not defined”.
I have tried to modify the “[B]$_SESSION
Here is my first file (the Index.php) file :
[code=php]<?php session_start();
$db_username = ‘xxxx’;
$db_password = ‘xxxxx’;
$db_name = ‘xxxxxx’;
$db_host = ‘localhost’;
$conn = new mysqli($db_host, $db_username, $db_password, $db_name);
$selected = mysqli_select_db($conn, “xxxxxxx”) or die(“Could not locate database getaqu : ” . mysqli_connect_error());
error_reporting(E_ALL & ~E_NOTICE);
if(isset($_POST[‘submit’])||isset($_POST[‘submit’])) {
$login = $_POST[‘login’];
$password = $_POST[‘password’];
$password2 = $_POST[‘password2’];
$firstname = $_POST[‘firstname’];
$surname = $_POST[‘surname’];
$email = $_POST[’email’];
$email2 = $_POST[’email2′];
$dateofbirth = $_POST[‘dateofbirth’];
$address = $_POST[‘address’];
$city = $_POST[‘city’];
$zipcode = $_POST[‘zipcode’];
$state = $_POST[‘state’];
$country = $_POST[‘country’];
$_SESSION[‘login’] = $_POST[‘login’];
$_SESSION[‘password’] = $_POST[‘password’];
$_SESSION[‘password2’] = $_POST[‘password2’];
$_SESSION[‘firstname’] = $_POST[‘firstname’];
$_SESSION[‘surname’] = $_POST[‘surname’];
$_SESSION[’email’] = $_POST[’email’];
$_SESSION[’email2′] = $_POST[’email2′];
$_SESSION[‘telephone’] = $_POST[‘telephone’];
$_SESSION[‘dateofbirth’] = $_POST[‘dateofbirth’];
$_SESSION[‘address’] = $_POST[‘address’];
$_SESSION[‘city’] = $_POST[‘city’];
$_SESSION[‘zipcode’] = $_POST[‘zipcode’];
$_SESSION[‘state’] = $_POST[‘state’];
$_SESSION[‘country’] = $_POST[‘country’];
$sql_insert = “INSERT INTO registration (login, password, email)
VALUES (‘$login’, ‘$password’, ‘$email’)”;
$result_insert = mysqli_query($conn,$sql_insert);
if ($result_insert) {
echo : ‘REGISTRATION COMPLETE ! Thank you’;
exit();
}
else {
echo “ERROR: Was not able to execute $sql. ” . mysqli_error($conn);
}
}
?>