Jump to content

[SOLVED] Issue Registering sessions via a loop


cooldude832

Recommended Posts

I'm trying out a new method of logging in and it looks like this:

<?php
function login(){
session_unset();
connectSQL();
$username = mysql_escape_string(trim($_POST['username']));
$password = md5(trim($_POST['password']));
// Create query
$fields = array("UserID","Username");
$sqlfields = implode(",",$fields);
$q = "SELECT '$sqlfields' FROM `Users` WHERE `Username`='$username' && `Password`='$password' LIMIT 1";
// Run query
$r = mysql_query($q) or die(mysql_error());
if(mysql_num_rows($r)){
	$row = mysql_fetch_array($r);
	foreach($fields as $value){
		$_SESSION[$value] = $row[$value];
	}
	// Redirect to member page
	$_SESSION['logged_in'] = "yes";
	header("Location: play.php");
}	
else{
  // Login not successful
die("Sorry, could not log you in. Wrong login information.<br/>");
include("login.html");
}
}//End of login
?>

It is working, to login, but when i try to retrive my registered sessions i get:

 

UserID :

Username :

logged_in : yes

off the code

<?php
foreach($_SESSION as $key => $value){
echo $key." : ".$value."<br />";
}
?>

any ideas?

 

Edit:

I've tried putting the $_SESSION[$value] = as $row["$value"] and as $row['$value'] with no luck

I've tried more sessions and they can't even register any ideas?

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.