我正在尝试查询mysql并获取要返回的结果,但是在尝试检查返回的结果数是否大于零时遇到了以下错误。这是我的代码:
<body>
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "cd";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
/*
$sql = "SELECT * FROM cdlist WHERE cdlist.title =" . $_POST["cd_name"]." OR cdlist.Artist=" .$_POST["artist_name"]. " OR cdlist.Price=" . $_POST["cd_price"] . " OR cdlist.Year=" . $_POST["year"];
*/
$sql = "SELECT * FROM cdlist WHERE cdlist.Title=" . $_POST["cd_name"];
//$sql = "SELECT * FROM cdlist";
$result = mysqli_query($conn, $sql);
$json_array = array();
if (mysqli_num_rows($result)>0){
while($row = mysqli_fetch_assoc($result)){
$json_array[] = $row;
}
echo json_encode($json_array);
}
$conn->close();
?>
</body>
php中的任何查询是否存在问题?我只能使它与SELECT * FROM cdlist一起使用,但这不是我要使用的查询。我知道cd_name也是变量的正确名称。感谢您能为我提供的任何帮助