Jump to content

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

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.