带有 php 的 mysqli where 子句出现错误

mysqli where clause with php getting error

我正在尝试使用 mysqli select where 子句和 php 中的变量,但我收到此错误

Error: Our query failed to execute and here is why: Query: SELECT * FROM Products WHERE 'ProductCategory' LIKE laptops Errno: 1054 Error: Unknown column 'laptops' in 'where clause'

  viewby.php
 <?php
 include('db/functions.php');
  $result= getproductsbycategory($_GET['ctg']);

while($product = $result->fetchassoc()){
    echo $product['ProductName'];
}

?>

//functions.php

 <?php
 function getproductsbycategory($ctg){
 include('connect.php');
     $sql = "SELECT * FROM Products WHERE 'ProductCategory' LIKE $ctg ";
 if(! $result = $mysqli->query($sql))
{
    echo "Error: Our query failed to execute and here is why: \n";
    echo "Query: " . $sql . "\n";
    echo "Errno: " . $mysqli->errno . "\n";
    echo "Error: " . $mysqli->error . "\n";
    exit;
}
return $result;
 }
  ?>
 //index.php

<a href="viewby.php?ctg=<?php echo $ctg; ?>">

 //viewby.php

<?php
 include('db/functions.php');
  $result= getproductsbycategory($_GET['ctg']);

while($product = $result->fetchassoc()){
    echo $product['ProductName'];
}

?>

我真的不知道是什么问题,如果我 运行 来自 phpmyadmin 的查询它工作正常,抱歉如果问题太明显 谢谢

尝试用这个来改变你的查询

 $sql = "SELECT * FROM Products WHERE `ProductCategory` LIKE '%$ctg%' ";

你插入的是单引号 ' 而不是这个 `