Jump to content

Why a normal variable keeps its value on another page


ejarnutowski

Recommended Posts

Hi guys/gals,

 

I have a variable $id that i'm declaring from a $_GET ( $id = $_GET['id'] ) and for some reason that $id variable still holds a value in other pages.  register globals is off and i don't think im declaring it as a global.  any idea what would make this happen?  my code is below.  if i go to another page and print out the $id variable, it contains the value from this page for some reason.

 

<?php
session_start();
include '_private/dbconnect.php';     //connecting to db

//if there's no id to get from the url, redirect to index.php
if (!isset($_GET['id'])){
header("location:index.php");
exit();
}

//query the users table to grab the row with the posted user id and store some data into variables
$id=$_GET['id'];
$query=mysql_query("SELECT * FROM users WHERE id='$id'");
$fetch=mysql_fetch_array($query);
$first_name = ucwords($fetch['first_name']);
$last_name = ucwords($fetch['last_name']);
$nh_city = ucwords($fetch['nh_city']);
$nh_state = strtoupper($fetch['nh_state']);
$current_votes = $fetch['current_votes'];

//query the users table to get the number of current candidates
$query=mysql_query("SELECT id FROM users WHERE acct_status !='disabled'");
$fetch=mysql_num_rows($query);
$total_girls = $fetch;

//query the users table and run a small loop to get the rank
$query=mysql_query("SELECT id, current_votes FROM users WHERE acct_status !='disabled' ORDER BY current_votes DESC");
$stop = "go";
$count = "0";
while ($stop != "stop"){
	$count = $count + 1;
	$fetch=mysql_fetch_array($query);
	if ($fetch['id'] == $id){
			$stop = "stop";
			$rank = $count;		
	}
}

//query the period table to get the start and end dates of this voting period
$query=mysql_query("SELECT datetime_start, datetime_end FROM period WHERE period='current'");
$fetch=mysql_fetch_array($query);
$period_start = substr($fetch['datetime_start'], 5, 2) . "/" . substr($fetch['datetime_start'], 8, 2) . "/" . substr($fetch['datetime_start'], 0, 4);
$period_end = substr($fetch['datetime_end'], 5, 2) . "/" . substr($fetch['datetime_end'], 8, 2) . "/" . substr($fetch['datetime_end'], 0, 4);

//query the photos table to get the primary photo information
$query = mysql_query("SELECT file_name, file_location FROM photos WHERE user_id='$id' and profile_photo='yes'");
$fetch = mysql_fetch_array($query);
$file_location = $fetch['file_location'];
$file_name = $fetch['file_name'];
//if there's no profile photo, a default picture is displayed
if (mysql_num_rows($query) < 1){
$no_photos = "true";
$file_location = "images/";
$file_name = "default_profile_picture.jpg";
}
?>

Hi,

 

Thanks for the input, but i'm fairly familiar with the language and have been coding with it for a few years.  great idea to check the phpinfo though.  before your post, i checked this setting through the control panel of my hosting account and register globals is set OFF but it's showing as turned on using phpinfo.  i'm contacting the hosting account now.  thanks for your help

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.