PDA

View Full Version : Help with login video tutorial


Bike Racer
04-21-2008, 01:52 AM
I really enjoy your tutorials!!! I'm having problems though with the login tutorial. I set up the login page and everything seems to be working fine.

<?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";
}

?>


This will kick me to the "success.php" page. When I add the php to the success page I get kicked out when logging in.


<?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);
/////////////////////////////



?>
It seems too me that SESSION id it not being set on the login page. If I take the ! out of isset I will not get kicked out.

Am I missing something?

Thanks

davidj
04-21-2008, 06:24 AM
comment out the ...

//header("location:success.php");

then echo the SESSION contents to see if its set with the user_id value when you try to log in

Bike Racer
04-21-2008, 12:44 PM
Thanks David,

///header("location:success.php");
echo $rowAccount['user_id'];
///exit;

returned - 1

Bike Racer
04-21-2008, 12:46 PM
///header("location:success.php");
echo $_SESSION['id'];
///exit;

Also returned 1

Bike Racer
04-21-2008, 01:03 PM
on success.php

This returned nothing

session_start();
echo $_SESSION['id']

davidj
04-22-2008, 06:05 AM
did you terminate the session with a semi colon

Bike Racer
04-22-2008, 10:51 AM
I did. My web hosting service is also looking into the problem. The sever behavior within DW created the same problem. - a correct username/password directs me back to the login page. Thanks for your help. If I sent you the link would you be willing to take a look at it?

davidj
04-23-2008, 06:12 AM
if you sent a link there wont be any php to troubleshoot