I'm converting this query into a prepared statement:
$stmt = "SELECT * FROM `table` WHERE col1 ='". $var1. "' and col2 = '".$var2."' and col3 ='".$var3."'";
$result = mysqli_query($db, $stmt);
$item_row=mysqli_fetch_row($result);
with it's result I echo out item_row[1]
, item_row[2]
, etc. This works fine.
This is the prepared statement I've put together, but it's not working:
$stmt = $db->prepare("SELECT * FROM `table` WHERE col1 = ? and col2 = ? and col3 =?");
$stmt->bind_param("sss", $var1,$var2,$var3);
$stmt->execute();
while ($item_row = $stmt->fetch()) {
print_r($item_row); // prints: 1
var_dump($item_row); // prints: bool(true)
}
I've tried using the code from How can I prevent SQL injection in PHP? but it breaks the whole page.
I've also read and tried examples from How can I prevent SQL injection in PHP?, but none work. The above example is the farthest I've gotten.
Any ideas what I need to do?