Jump to content

session problems...


blueman378

Recommended Posts

hi guys, well i am trying to use this code:

include("database.php");
$username = $_REQUEST['username'];
$password = $_REQUEST['password'];
$password = md5($password);
global $database;
    $q = "SELECT * FROM users
          WHERE username = '$username' AND password = '$password'
         ";   
    $result = $database->query($q) or die("Error: " . mysql_error());
    $num_rows = mysql_numrows($result);

if( $num_rows == 1 ){
      session_start();
$_SESSION['username'] = $row['username'];
$_SESSION['userid'] = $row['id'];
$_SESSION['userlevel'] = $row['userlevel'];
$_SESSION['loggedin'] = "TRUE";
echo "hello";  
echo $_SESSION['username'];
}

which works... kindof

$_SESSION['username']

$_SESSION['userid']

$_SESSION['userlevel']

do not seem to be getting set as if i change

"echo $_SESSION['username'];" to echo $_SESSION['loggedin'];

it will echo true,

however if i have it as anything else, nothing gets echoed,

i know that the information is getting retrieved from the database as the code itself is running,

 

any ideas?

Link to comment
Share on other sites

try this:

 

<?php
session_start();
include("database.php");

$username = mysql_real_escape_string($_REQUEST['username']);
$password = md5($_REQUEST['password']);
global $database;
$q = "SELECT * FROM users WHERE username = '$username' AND password = '$password'";   
$result = $database->query($q) or die("Error: " . mysql_error());

if(mysql_num_rows($result)==1){
$row=mysql_fetch_array($result);
$_SESSION['username'] = $row['username'];
$_SESSION['userid'] = $row['id'];
$_SESSION['userlevel'] = $row['userlevel'];
$_SESSION['loggedin'] = "TRUE"; 
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.