Jump to content

Session Confusion?? :S


Vivid Lust

Recommended Posts

Hi, I think there is some confusion with sessions in my script, but not being that good at PHP I dont know how to fix this.

 

I am getting "name" from a row from a database where the id is equal to a variable ($_GET['id'])

When there is no sessions registered this works fine.

However, when, say someone name is "foo" and they have their session registered, then on every GET, their name is displayed, even if they have the ID of 5, and the current ID is 2348 then their name is still echoed.

 

My script for this page:

<?php
// start session and include db info
require("includes/db.php");

//get user id
$id = $_GET['id']; 

//get info about user from database
$sql = "SELECT name, gender, about, s_phish, u_phish, p_phish, p_s, location FROM users WHERE id=( \"$id\" )";
$query=mysql_query($sql, $link)
or die(mysql_error());
while($row=mysql_fetch_assoc($query)){
$name     =  $row['name'];
$gender   =  $row['gender'];
$about    =  $row['about'];
$location =  $row['location'];
$s_phish  =  $row['s_phish'];
$u_phish  =  $row['u_phish'];
$p_phish  =  $row['p_phish'];
$p_s      =  $row['p_s'];
}

?>
<?php 
session_start();
?>
<?php include("siteincludes/header.php"); ?> 
<!-- content block START -->
<div id="conent">
<?php include("siteincludes/sidebar.html"); ?>
	<!-- left column start-->
	<div class="left_col">
		<div class="db1">
			<div class="db1_title">
				<h3><?php echo $name;  ?>'s Profile</h3> 

 

Any ideas? I personally cant see whats wrong.

Any help is appreciated!

Link to comment
https://forums.phpfreaks.com/topic/124199-session-confusion-s/
Share on other sites

Try this:

 

<?php
session_start();
// start session and include db info
include("includes/db.php");

//get user id
$id = $_GET['id']; 

//get info about user from database
$sql = "SELECT name, gender, about, s_phish, u_phish, p_phish, p_s, location FROM users WHERE id = '$id' ";
$query=mysql_query($sql, $link) or die (mysql_error());
while($row=mysql_fetch_assoc($query)){
$name     =  $row['name'];
$gender   =  $row['gender'];
$about    =  $row['about'];
$location =  $row['location'];
$s_phish  =  $row['s_phish'];
$u_phish  =  $row['u_phish'];
$p_phish  =  $row['p_phish'];
$p_s      =  $row['p_s'];
}

?>
<?php include("siteincludes/header.php"); ?> 

Link to comment
https://forums.phpfreaks.com/topic/124199-session-confusion-s/#findComment-641333
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.