title: php mysql not pulling data correctly
body: <p>so i am trying to have a table show what hills have been ridden by bikers (getting ready for the MS150). my issue is that when a person clicks on the button to say they have ridden the hill ... it is only working some of the time. when they say they have done a hill, the button disables and they aren't allowed to push it again. but, some of the records aren't showing up correctly. here's my code: </p>
  
  <p>html:</p>
  
  <pre><code>$get_hills = "SELECT * FROM hills ORDER BY hill_region ASC, hill_id ASC"; 
  $run_hills = mysqli_query($con, $get_hills); 
  while($row_hills = mysqli_fetch_array($run_hills)) {
  
  $hill_id = $row_hills['hill_id'];
  
  $get_user = "SELECT * FROM users WHERE user_id = '".$_SESSION['user_id']."'";
  $run_user = mysqli_query($con, $get_user); 
  $row_user = mysqli_fetch_array($run_user); 
  
  $get_ridden = "SELECT * FROM hills_ridden WHERE hill_id = '".$hill_id."'";
  $run_ridden = mysqli_query($con, $get_ridden);
  $row_ridden = mysqli_fetch_array($run_ridden); 
  echo "
  &lt;tr&gt;
  &lt;td&gt;".$row_hills['hill_name']."&lt;/td&gt;
  &lt;td&gt;".$row_hills['hill_region']."&lt;/td&gt;
  &lt;td&gt;".$row_hills['hill_rise']."&lt;/td&gt;
  &lt;td&gt;".$row_hills['hill_length']."&lt;/td&gt;
  &lt;td&gt;".$row_hills['hill_avg_grade']."&lt;/td&gt;
  &lt;td&gt;".$row_hills['hill_total_points']."&lt;/td&gt;
  &lt;td&gt;&lt;a href='".$row_hills['hill_link']."' target='_blank'&gt;&lt;button class='btn btn-inverse btn-xs'&gt;Link&lt;/button&gt;&lt;/a&gt;&lt;/td&gt;
  &lt;td&gt;";
  if($row_user['user_id'] == $row_ridden['user_id']) {
  echo "&lt;button class='btn btn-default btn-xs' disabled&gt;You Rode This&lt;/button&gt;";
  } else {
  echo"
  &lt;form method='post' action=''&gt;
  &lt;input type='hidden' name='hill_id' value='".$row_hills['hill_id']."'&gt;
  &lt;input type='hidden' name='points_gained' value='".$row_hills['hill_total_points']."'&gt;
  &lt;input type='hidden' name='user_id' value='".$row_user['user_id']."'&gt;
  &lt;button type='submit' name='hill_sub' class='btn btn-inverse btn-xs'&gt;I Rode This&lt;/button&gt;
  &lt;/form&gt;";
  } echo"&lt;/td&gt;
  &lt;/tr&gt;";
  }
  </code></pre>
  
  <p>php: </p>
  
  <pre><code>if(isset($_POST['hill_sub'])) {
  
  $get_user = "SELECT * FROM users WHERE user_id = '".$_SESSION['user_id']."'";
  $run_user = mysqli_query($con, $get_user); 
  $row_user = mysqli_fetch_array($run_user);
  
  $insert_points = "INSERT INTO points (user_id, hill_id, points_gained, points_date) VALUES ('".$row_user['user_id']."', '".$_POST['hill_id']."', '".$_POST['points_gained']."', now())"; 
  
  $insert_activity = "INSERT INTO activity (user_id, hill_id, activity_date) VALUES ('".$row_user['user_id']."', '".$_POST['hill_id']."', now())"; 
  
  $insert_hill = "INSERT INTO hills_ridden (user_id, hill_id) VALUES ('".$row_user['user_id']."', '".$_POST['hill_id']."')"; 
  
  $run_points = mysqli_query($con, $insert_points); 
  $run_activity = mysqli_query($con, $insert_activity); 
  $run_hills = mysqli_query($con, $insert_hill); 
  
  if($run_hills) {
      echo "&lt;script&gt;window.open('record-hill.php?user_id=".$row_user['user_id']."', '_self')&lt;/script&gt;"; 
  } else {
      echo $run_hills-&gt;error; 
  }
  }
  </code></pre>
  
  <p>and here's the sql db file: </p>
  
  <pre><code>-- Table structure for table `hills_ridden`
  --
  
  CREATE TABLE IF NOT EXISTS `hills_ridden` (
  `ridden_id` int(11) NOT NULL AUTO_INCREMENT,
  `user_id` varchar(5) NOT NULL,
  `hill_id` varchar(5) NOT NULL,
  PRIMARY KEY (`ridden_id`)
  ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=33 ;
  </code></pre>
  
  <p>any help would be appreciated ... i have been trying different queries to make it work, but have been unsuccessful for the past 2 days :/ PLEASE!! </p>