I am trying to embed mysqli code into my web page so I can eliminate sql injection. Here is what my code looks like right now:
$gYear = $_POST["year"];
$gYear2 = $_POST["year2"];
$gMonth = $_POST["month"];
$gSelect = $_POST["location"];
$query = $conn->prepare("SELECT $gSelect, Year FROM unemployed WHERE year BETWEEN '$gYear' AND '$gYear2' and month='$gMonth'");
$query->bind_param('ssss', $gyear, $gYear2, $gMonth, $gSelect);
$query->execute();
$result = $query->get_result();
while ($row = $result->fetch_object()){
// do something with gathered rows
}
Now, once the form is submitted, I get two errors. Here is what they say:
Warning: mysqli_stmt::bind_param() [mysqli-stmt.bind-param]: Number of variables doesn't match number of parameters in prepared statement in
AND
Fatal error: Call to undefined method mysqli_stmt::get_result() in
I really don't know what my issue is. I tried to follow the rules listed in How can I prevent SQL injection in PHP?. Does anyone know what my issues are? Why am I receiving these two error messages? Any help would be greatly appreciated.