There were many times I faced this problem. The format is correct (.php), connection to the localhost server seems to be fine, cause some of the .php insertions are working.
For example(here .php insertion is working),
...(some html)...<div class="menu">
<ul>
<li><a href="#" class="active">Главная</a></li>
<li><a href="#">Товары</a></li>
<li><a href="#">Контакты</a></li>
<li><a href="#">FAQ</a></li>
<li><a href="#"><i class="fas fa-shopping-cart"></i></a></li>
<li><a href="registration.php"><i class="fas fa-user"></i>
<?php
echo($_COOKIE['client']);
?>
</a></li>
</ul>
</div>...(some html)..
echo is working
The same file when I'm trying other .php insertion stops loading the page and finishes right before <?php...
To see what I'm talking about I made some screenshots browser trnascript full html file
As you see, browser ignores and leaves empty all the code after and including <?php...
To be exact:
<div class="container">
<div class="row row-eq-height text-center py-5 px-4">
<?php
$result = $database->getData();
while ($row = mysqli_fetch_assoc($result)){
component($row['product_name'], $row['product_price'], $row['product_img'], $row['id']);
}
?>
</div>
</div>
Browser reads this file until the start of php(<?php) and doesn't display anything after
I'm a beginner trying to build a website, maybe there is something I missed Please help!!!
getData should return all the information from the table
// get product from the database
//tablename refers to my own existing table with products
public function getData(){
$sql = "SELECT * FROM $this->tablename";
$result = mysqli_query($this->con, $sql);
if(mysqli_num_rows($result) > 0){
return $result;
}
}
Then I'm using loop shown above to fill the product sample
<?php
function component($productname, $productprice, $productimg, $productid){
$element = "
<div class=\"col-md-3 col-sm-6 my-3 my-md-0\">
<form action=\"index.php\" method=\"post\">
<div class=\"card shadow\">
<div>
<img src=\"$productimg\" alt=\"Image1\" class=\"img-fluid card-img-top\">
</div>
<div class=\"card-body\">
<h5 class=\"card-title\">$productname</h5>
<h6>
<i class=\"fas fa-star\"></i>
<i class=\"fas fa-star\"></i>
<i class=\"fas fa-star\"></i>
<i class=\"fas fa-star\"></i>
<i class=\"far fa-star\"></i>
</h6>
<p class=\"card-text\">
Some quick example text to build on the card.
</p>
<h5>
<small><s class=\"text-secondary\">$519</s></small>
<span class=\"price\">$$productprice</span>
</h5>
<button type=\"submit\" class=\"btn btn-warning my-3\" name=\"add\">Add to Cart <i class=\"fas fa-shopping-cart\"></i></button>
<input type='hidden' name='product_id' value='$productid'>
</div>
</div>
</form>
</div>
";
echo $element;
}
?>