Home > Mobile >  While running my shopping cart page, i get mysqli_fetch_array() expects parameter 1 to be mysqli_res
While running my shopping cart page, i get mysqli_fetch_array() expects parameter 1 to be mysqli_res

Time:01-25

while running the code im getting tis error : mysqli_fetch_array() expects parameter 1 to be mysqli_result error


$result = mysqli_query($dbc,"select * from 'product'");
while($row = mysqli_fetch_assoc($result)){
        echo "<div class='product_wrapper'>
              <form method='post' action=''>
              <input type='hidden' name='cat' value=".$row['Product_Category']." />
              <div class='image'><img src='".$row['Product_Img']."' /></div>
              <div class='name'>".$row['Product_Name']."</div>
              <div class='price'>$".$row['Product_Price']."</div>
              <button type='submit' class='buy'>Buy Now</button>
              </form>
              </div>";
        }
mysqli_close($dbc);

CodePudding user response:

Below is the working example on my laptop using xampp,

<?php 
$dbc = mysqli_connect('localhost', 'USERNAME', 'PASSWORD', 'TABLE_NAME');
if (mysqli_connect_errno()) {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  exit();
}
$result = mysqli_query($dbc, "select * from product");
while($row = mysqli_fetch_assoc($result)){
        echo "<div class='product_wrapper'>
              <form method='post' action=''>
              <input type='hidden' name='cat' value=".$row['Product_Category']." />
              <div class='image'><img src='".$row['Product_Img']."' /></div>
              <div class='name'>".$row['Product_Name']."</div>
              <div class='price'>$".$row['Product_Price']."</div>
              <button type='submit' class='buy'>Buy Now</button>
              </form>
              </div>";
        }
mysqli_close($dbc);
?>
  • Related