title: Results aren't being gathered from my database after trying to prevent sql injection
body: <p>I am currently trying to prevent sql injection by using mysqli statements. However, after completing this transition, I am not getting results from my database anymore. I have a form where users can select economic data by narrowing down year intervals, months out of the year, and a location.Here is my current coding issues: </p>
  
  <pre><code>&lt;?php
  
  if (isset($_POST['submitted'])) {
  
  
  $gYear = $_POST["year"];
  $gYear2 = $_POST["year2"];
  $gMonth = $_POST["month"];
  $gSelect = $_POST["location"];
  
  if ($gYear &gt; $gYear2) {
  
  die('ERROR: Your second year cant be a time period before the first year you selected');
  }
  
  else {
  
  $query = $conn-&gt;prepare("SELECT $gSelect, Year FROM unemployed WHERE year BETWEEN ? AND ? and month= ?");
  $query-&gt;bind_param('sss', $gyear, $gYear2, $gMonth);
  
  $query-&gt;execute(); 
  
  $result = = $conn-&gt;query($query)
  
  echo"&lt;table&gt;";
  echo "&lt;tr&gt;&lt;th&gt;Year&lt;/th&gt;&lt;th&gt;Time&lt;/th&gt;&lt;th&gt;$gSelect&lt;/th&gt;&lt;/tr&gt;";
  
  while ($row = $result-&gt;fetch_object()){
  
  
  echo "&lt;tr&gt;&lt;td&gt;";
  echo $row-&gt;Year;
  echo "&lt;/td&gt;&lt;td&gt;";
  echo $gMonth;
  echo "&lt;/td&gt;&lt;td&gt;";
  echo $row-&gt;$gSelect;
  echo "&lt;/td&gt;&lt;/tr&gt;";
  
  }
  
  
  
  
  echo "&lt;/table";
  
  }
  
  } // end of main if statement
  
  ?&gt;
  </code></pre>
  
  <p>It worked before I tried updating my query to prevent injection. I am currently using php 5.2.14 to work on this in case you guys were wondering. Am I missing a statement? Can anyone help me figure out what my issue is? Any help would be greatly appreciated. </p>