简单地。如果我想将产品添加到购物车php中工作,但是如果我尝试将产品添加到特定表中则无法工作。我试图设置if(!con){echo“ test”;}或类似的地方我可以找出问题所在,但是php不会显示任何错误。所有会话均正常工作,数据库已连接。有任何建议吗?问题可能在mysql表中,但不会显示任何内容。上次我在varchar中出错时,sql显示了一些东西但这一次...什么都没有!对不起我的英语差错xD!
Function.php
function favor(){
if(isset($_GET['add_favor'])){
global $con;
$ip = getIp();
$pro_id = $_GET['add_favor'];
$user = $_SESSION['customer_username'];
$check_favor = "SELECT * FROM favorite WHERE username='$user' AND pro_id='$pro_id'";
$run_fcheck = mysqli_query($con, $check_favor);
if(mysqli_num_rows($run_fcheck) == 0){
$insert_favor = "INSERT INTO favorite (pro_id,username) VALUES ('$pro_id','$user')";
$run_favor = mysqli_query($con, $insert_favor);
echo "<script>window.open('index.php','_self')</script>";
}
}
}
index.php
<?php include 'header.php'; ?>
<?php cart(); ?>
<?php favor(); ?>
<div class="sidebar">
<div class="spacer2"></div>
<?php getCats(); ?>
</div>
<div class="content">
<li style="margin-top:10px;" class="search42">
<form method="get" action="results.php" enctype="multipart/form-data">
<input class="afsc2g" type="text" name="user_query" placeholder="Search.." name="search">
<button type="submit" name="search"><i class="fa fa-search"></i></button>
</form></li>
<div class="content-nav">
<a href="shopping_cart.php"><i class="fas fa-shopping-cart"></i><span> (<?php total_price(); ?> din.)</span></a>
</div>
<div class="products" style="height:200px;">
<?php
if(isset($_GET['pro_id'])){
$user = $_SESSION['customer_username'];
$product_id = $_GET['pro_id'];
$get_pro = "SELECT * FROM products WHERE product_id='$product_id'";
$run_pro = mysqli_query($con, $get_pro);
while($row_pro=mysqli_fetch_array($run_pro)){
$pro_id = $row_pro['product_id'];
$pro_title = $row_pro['product_title'];
$pro_price = $row_pro['product_price'];
$pro_desc = $row_pro['product_desc'];
$pro_image = $row_pro['product_image'];
echo "<div class='divbox'>
<div style='float:left'>
<h2 style='font-size:27px'>$pro_title</h2>
<img style='border-top:3px solid #1585bd;' width='450px' height='450px' src='../assests/pictures/products/$pro_image'/>
</div>
<div class='ukorpu'>
<a class='add_favor'><a class='button' href='index.php?add_favor=$pro_id'><i class='fas fa-star'></i></a>
<a class='cena' style='font-size:23px;'>$pro_price din.</a>
<a style='position:absolute;left:72px;top:50px;font-size:14px;'>sa PDV-om</a>
<a class='bnau2' style='font-weight:bold;' href='index.php?add_cart=$pro_id'><i class='fas fa-shopping-cart'></i> Dodaj u korpu</a></p>
</div></div>
<div class='desc'>
<div class='desc-desc'>
$pro_desc
</div>
</div>";
}
}
?>
MySQL表: