php Newbie having problem with $_SESSION
Posted: Mon Apr 21, 2008 10:44 am
Trying to put together a login screen-
<?php
require_once("Connections/testserver.php");
session_start();
//Catch Field Data
$userid = $_POST['userid'];
$password = $_POST['password'];
$submitted = $_POST['submitted'];
if ($userid && $password) {
/////////////////////////////////////////////
$query = sprintf("SELECT * FROM night where user_name='$userid' and user_password = '$password'");
$result = mysql_query($query);
$rowAccount = mysql_fetch_array($result);
/////////////////////////////////////////////
}
if ($rowAccount) {
$_SESSION['id'] = $rowAccount['user_id'];
header("location:success.php");
exit;
}elseif($submitted){
echo "You don't exist on our database";
}
?>
I echoed $_SESSION['id} on this page and got a result.
on my welcome page - success.php - I get kicked back to my login page.
<?php
require_once("Connections/testserver.php");
session_start;
if (!isset($_SESSION['id'])){
header("location: mylogin.php");
exit;
}
$id = $_SESSION['id'];
////////////////////////////
$query =sprintf("SELECT * FROM night where user_id='$id'");
$result =mysql_query($query);
$rowAccount =mysql_fetch_array($result);
/////////////////////////////
?>
I echoed $_SESSION['id'] on this page and got a blank.
Am I missing something??
<?php
require_once("Connections/testserver.php");
session_start();
//Catch Field Data
$userid = $_POST['userid'];
$password = $_POST['password'];
$submitted = $_POST['submitted'];
if ($userid && $password) {
/////////////////////////////////////////////
$query = sprintf("SELECT * FROM night where user_name='$userid' and user_password = '$password'");
$result = mysql_query($query);
$rowAccount = mysql_fetch_array($result);
/////////////////////////////////////////////
}
if ($rowAccount) {
$_SESSION['id'] = $rowAccount['user_id'];
header("location:success.php");
exit;
}elseif($submitted){
echo "You don't exist on our database";
}
?>
I echoed $_SESSION['id} on this page and got a result.
on my welcome page - success.php - I get kicked back to my login page.
<?php
require_once("Connections/testserver.php");
session_start;
if (!isset($_SESSION['id'])){
header("location: mylogin.php");
exit;
}
$id = $_SESSION['id'];
////////////////////////////
$query =sprintf("SELECT * FROM night where user_id='$id'");
$result =mysql_query($query);
$rowAccount =mysql_fetch_array($result);
/////////////////////////////
?>
I echoed $_SESSION['id'] on this page and got a blank.
Am I missing something??