BabylonHoruv Posted August 7, 2014 Share Posted August 7, 2014 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. Quote Link to comment https://forums.phpfreaks.com/topic/290342-_session-data-vanishing/ Share on other sites More sharing options...
Jacques1 Posted August 7, 2014 Share Posted August 7, 2014 What is $_SERVER['user_id']? I'm fairly sure you mean $_SESSION['user_id']. Quote Link to comment https://forums.phpfreaks.com/topic/290342-_session-data-vanishing/#findComment-1487150 Share on other sites More sharing options...
BabylonHoruv Posted August 8, 2014 Author Share Posted August 8, 2014 What is $_SERVER['user_id']? I'm fairly sure you mean $_SESSION['user_id']. You are correct Quote Link to comment https://forums.phpfreaks.com/topic/290342-_session-data-vanishing/#findComment-1487151 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.