"how to remove the fatal error when fetching an assoc array" Answer’s


The variable $stmt is of type mysqli_stmt, not mysqli_result. The mysqli_stmt class doesn't have a method "fetch_assoc()" defined for it.

You can get a mysqli_result object from your mysqli_stmt object by calling its get_result() method. For this you need the mysqlInd driver installed!

$result = $stmt->get_result();
row = $result->fetch_assoc();

If you don't have the driver installed you can fetch your results like this:

$stmt->bind_result($dbUser, $dbEmail);
while ($stmt->fetch()) {
    printf("%s %sn", $dbUser, $dbEmail);

So your code should become:

$query = "SELECT Username, Email FROM User WHERE User = ?";
// prepare query
// You only need to call bind_param once
// execute query
// bind variables to result
$stmt->bind_result($dbUser, $dbEmail);
//fetch the first result row, this pumps the result values in the bound variables
    echo 'result is ' . dbEmail;
Wednesday, March 31, 2021
answered 10 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :