Jump to content

$_SESSION data vanishing


BabylonHoruv

Recommended Posts

So I am trying to make a page which creates a house as determined by a player.  The house is a row in a mySQL table with a field for the house ruler, which should be a number matching the ID of the player that created the house.  Whenever I attempt to create a house no data is entered into the table.  When I turned on all error reporting it told me that user_id was an invalid index and when I replaced it with an integer the data was entered into the table.

 

Here is the code to insert the data into the table.

	// write new house data into database			$importance = 0;			$ruler = $_SERVER['user_id'];			$query_new_house_insert = $this->db_connection->prepare('INSERT INTO houses (house_name, planet, importance, ruler) VALUES(:house_name, :planet, :importance, :ruler)');			$query_new_house_insert->bindValue(':house_name', $house_name, PDO::PARAM_STR);			$query_new_house_insert->bindValue(':planet', $planet, PDO::PARAM_STR);			$query_new_house_insert->bindValue(':importance', $importance, PDO::PARAM_STR);			$query_new_house_insert->bindValue(':ruler', $ruler, PDO::PARAM_STR);			$query_new_house_insert->execute();			 			
 
And here is the code to assign $_SERVER['user_id'] from the login script.

	if (http://www.php.net/isset($result_row->user_id)) {			// write user data into PHP SESSION [a file on your server]			$_SESSION['user_id'] = $result_row->user_id;			$_SESSION['user_name'] = $result_row->user_name;			$_SESSION['user_email'] = $result_row->user_email;			$_SESSION['user_logged_in'] = 1;			 			

 

I put in echos for the user id and on the page after log in it displays correctly and also on the form page to submit information to create the new house.  However it still shows as invalid in the code to actually create the house.  The code is in a separate file, which is included into the page.  It also includes its own session_start.  I tried commenting this out and that made $_SESSION an unrecognized variable.

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.