I'm trying to run a select statement on a table called test2. It's a very simple table with a username and password column. I don't understand how to access the result of the query. I want to be able to check if the username and password sent through the POST form match a username and password in my test2 table. Right now I'm just trying to get the query to work and print out the result. I got most of this code from the documentation here http://php.net/manual/en/mysqli-stmt.get-result.php
$link = mysqli_connect(HOST,USERNAME,PASSWORD,DBNAME) or die ("Connect Error" . mysqli_error($link));
$query = "SELECT username, password FROM test2 where username =? AND password =?";
$stmt = mysqli_stmt_init($link);
if(!mysqli_stmt_prepare($stmt, $query))
{
print "Failed to prepare statement\n";
}
else{
mysqli_stmt_bind_param($stmt,"ss", $_POST['user'], $_POST['pw']);
mysqli_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
$numRows = $result->mysqli_num_rows;
if ($numRows == 1){
echo "User exists";
}else{
echo "No users";
}
}
mysqli_close($stmt);
mysqli_close($link);