Trouble converting mysql statement to a mysqli prepared statement

Im in the proces of learning and converting some mysql statements into mysqli prepared statements :slight_smile: However i am stuck with this one >:( anybody able to help?

The error i get is

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, object given in…

My understanding is that this error is due to my while loop failing due to it not obtaining some needed criterea…however i have no idea why as it works perfectly if i dont use a prepared statement, and i just cant figure out whats going on.

Any help would be greatly appreciated.

The code is…

[php]<?php
$dbc = mysqli_connect(“localhost”, “root”, “pass”, “database”) or die("Problem connecting: ".mysqli_error());

$Output = “”;
if (!isset($_SESSION[“array”]) || count($_SESSION[“array”]) < 1) {
$Output = “

No data to render page

”;
}

else {
$i = 0;
foreach ($_SESSION[“previously_saved_array”] as $each_item){
$unique_id = $each_item[“unique_id”];
$query = “SELECT firstname, lastname, location FROM people WHERE id=?”;
$stmt = mysqli_prepare($dbc, $query) or die(mysqli_error($dbc));
mysqli_bind_param($stmt, “i”, $unique_id);
mysqli_stmt_execute($stmt);

		/* do i need to store the result??? is there any down side in doing so */

		$result = mysqli_stmt_store_result($stmt);

		/* ive tried using $row = mysqli_fetch_array($result) below aswel to no avail */

		while($row = mysqli_fetch_array($stmt)) {
		$fname = $row["firstname"];
		$lname = $row["lastname"];
		$uname = $row["location"];
		}

		$cartOutput .= 'Name: ' .$fname. ' ' .$lname. '<br />' .$uname. '<br /><br />';

	mysqli_free_result($result);
	mysqli_stmt_close($stmt);
	mysqli_close($dbc);
		}

}
?>[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service