Vivid Lust Posted September 14, 2008 Share Posted September 14, 2008 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! Quote Link to comment https://forums.phpfreaks.com/topic/124199-session-confusion-s/ Share on other sites More sharing options...
Vivid Lust Posted September 14, 2008 Author Share Posted September 14, 2008 Any ideas? :'( Quote Link to comment https://forums.phpfreaks.com/topic/124199-session-confusion-s/#findComment-641319 Share on other sites More sharing options...
budimir Posted September 14, 2008 Share Posted September 14, 2008 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"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/124199-session-confusion-s/#findComment-641333 Share on other sites More sharing options...
Vivid Lust Posted September 14, 2008 Author Share Posted September 14, 2008 I fixed the problem by removing the, session_start(); Weird, but it works now. Quote Link to comment https://forums.phpfreaks.com/topic/124199-session-confusion-s/#findComment-641346 Share on other sites More sharing options...
redarrow Posted September 14, 2008 Share Posted September 14, 2008 THAT MEANS YOU GOT SESSIONS_START TO AUTOMATICKLY BE ON IN YOUR PHP CONFIG MATE.......... Quote Link to comment https://forums.phpfreaks.com/topic/124199-session-confusion-s/#findComment-641352 Share on other sites More sharing options...
Vivid Lust Posted September 14, 2008 Author Share Posted September 14, 2008 well now it keeps on cancelling my session when i visit that page help please???? Quote Link to comment https://forums.phpfreaks.com/topic/124199-session-confusion-s/#findComment-641405 Share on other sites More sharing options...
burn1337 Posted September 14, 2008 Share Posted September 14, 2008 Maybe try passing the id through sessions instead of through the address bar... Quote Link to comment https://forums.phpfreaks.com/topic/124199-session-confusion-s/#findComment-641413 Share on other sites More sharing options...
DarkWater Posted September 14, 2008 Share Posted September 14, 2008 THAT MEANS YOU GOT SESSIONS_START TO AUTOMATICKLY BE ON IN YOUR PHP CONFIG MATE.......... I think your caps lock key is broken. @Thread starter: Did it display any errors when you had session_start() in there? Quote Link to comment https://forums.phpfreaks.com/topic/124199-session-confusion-s/#findComment-641427 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.