<?php
include_once("db_connection.php");
function component($productimage,$productname,$producttext,$productdiscount,$productprice,$productid){
$element = "
<div class=\"col-md-4 col-sm-6 my-3 my-md-0\">
<form action=\"index.php\" method=\"post\">
<div class=\"card shadow\">
<a href='./index.php?product=$productid'>
<div id=\"card-top\">
<img src=\"$productimage\" alt=\"$productname\" class=\"img-fluid card-img-top\">
</div>
<div class=\"card-body\">
<h5 class=\"card-title\">
$productname
</h5>
</a>
<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\" id=\"description\">
$producttext
</p>";
if($productprice==$productdiscount){
$element.="<h5>
<span class='price' id='disc'> $productprice P</span>
</h5>";
}
else{
$element.="<h5>
<small><s class='text-secondary' id='nondisc'>$productdiscount</s></small>
<span class='price' id='disc'> $productprice P</span>
</h5>";
};
$sql = "SELECT * FROM zakaz WHERE Prod_id=".$productid.";";
var_dump($sql);
$result = mysqli_query($conn,$sql);
$resultCheck = mysqli_num_rows($result);
if ($resultCheck > 0){
$element.="<button type='submit' href='./index.php' class='btn btn-warning my-3' name='add'>Добавить в корзину</button>
<input type='hidden' name='product_id' value='$productid'>";}
else{
$element.="<button type='submit' href='./index.php' class='btn btn-warning my-3' name='add' disabled>Добавлено в корзину</button>
<input type='hidden' name='product_id' value='$productid'>";
};
$element.="
</div>
</div>
</form>
</div>";
echo $element;
}
?>
<?php
$dbServername = "localhost";
$dbUsername="root";
$dbPassword="";
$dbName="kursor";
$conn=mysqli_connect($dbServername,$dbUsername,$dbPassword,$dbName);
if (!$conn){
die("Connection failed: ".mysqli_connect_error());
}
?>
global $conn;
. Конечно возможен и третий способ, include("db_connection.php");
внутрий функции, но это уже махровый быдлокодеризм и тупая растрата свободных подключений к MySQL. <div class=\"col-md-4 col-sm-6 my-3 my-md-0\">
<form action=\"index.php\" method=\"post\">
<div class=\"card shadow\">
<a href='./index.php?product=$productid'>
<div class="col-md-4 col-sm-6 my-3 my-md-0">
<form action="index.php" method="post">
<div class="card shadow">
<a href="./index.php?product=<?=$productid?>">
<div id="card-top">