Home > database >  Im having a problem while running my shopping cart page
Im having a problem while running my shopping cart page

Time:01-24

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