我无法回显行数,如果行数为零,则不会显示警报。
警告:mysqli_query()至少需要2个参数,在 45 <45>行的 C:\ xampp \ htdocs \ cart7 \ cart_view.php 中给出1个参数。 / strong>
警告:mysqli_fetch_assoc()期望参数1为mysqli_result,在 C:\ xampp \ htdocs \ cart7 \ cart_view.php 中给定null
<?php
include 'includes/conn.php';
session_start();
$result=mysqli_query("SELECT count(*) as total from cart");
$data=mysqli_fetch_assoc($result);
echo $data['total'];
if(!$data) {
echo "<script>
alert('Empty Cart');
{
window.location.href='index.php';
}
</script>";
}
if(isset($_SESSION['admin'])){
header('location: admin/home.php');
}
if(isset($_SESSION['user'])){
$conn = $pdo->open();
try{
$stmt = $conn->prepare("SELECT * FROM users WHERE id=:id");
$stmt->execute(['id'=>$_SESSION['user']]);
$user = $stmt->fetch();
}
catch(PDOException $e){
echo "There is some problem in connection: " . $e->getMessage();
}
$pdo->close();
}
?>
我已经尝试过了,但是仍然无法正常工作
$result=mysqli_query("SELECT count(*) as total from cart");
$data=mysqli_fetch_assoc($result);
echo $data['total'];
if(!$data){
}