Jump to content

BabylonHoruv

New Members
  • Posts

    2
  • Joined

  • Last visited

BabylonHoruv's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. 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.
  2. So I am fairly new to PHP. I have dabbling experience in a slew of languages, C++, Python, Java, Perl, Javascript, Haskell and I am fluent in HTML but not so great with CSS. I am currently working on developing a browser game using PHP and am going to be asking for help making it work. When I ask stupid questions, as I am sure I will, I hope people will help me learn to ask better ones.
×
×
  • 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.