【发布时间】:2017-09-22 00:07:31
【问题描述】:
我正在尝试搜索数据库中位于某个郊区的所有房产。我已经读到它与 HTML 代码 204 有关,但我仍然不明白该做什么或它的真正含义。我有一段时间没有做过任何 JS 或 PHP,所以这可能是一个非常愚蠢的错误,但我终其一生都无法弄清楚。请帮忙!
这是我的 JS 代码:
function basicSearch(){
//Connect Script to the PHP
var urlLink = "basicSearch.php";
//Get search parameters:
var searchAreaBar = document.getElementById("searchAreaBar").value;
//define the parameters to send to php
var strParameters = "searchAreaBar="+searchAreaBar + "&sid=" + Math.random();
// define the options for the AJAX request
var objOptions = {
// use method post
method: "post",
// use strParameters as the parameters
parameters: strParameters,
// if successfil call fuction(objXHR)
onSuccess: function(objXHR) {
// if objXHR. responseText = yes
if(objXHR.responseText=='Yes'){
alert("Success!");
}
else{
alert("Error! No Properties Found!");
}
}
}
// define the AJAX request object
var objRequest = new Ajax.Request(urlLink,objOptions);
}
这是我的 PHP 代码:
<?php
//Link the username and password:
$connect = mysqli_connect("localhost", "admin", "12345", "realestate") or die ('Connection to database failed: ' . mysql_error());
//Extract variables for request parameters:
extract($_REQUEST);
//Define the query:
$BasicSearch = "SELECT * FROM properties WHERE Suberb='$searchAreaBar'";
//Run the query:
$resDasicSearch = mysqli_query($BasicSearch) or die(mysql_error());
//SET intCount to number of rows in result:
$intCount = mysqli_num_rows($resDasicSearch);
//If intCount is greater than 0:
if($intCount > 0){
//Echo Yes:
echo "Yes";
}
else{
//Echo no:
echo "No";
}
?>
提前致谢。
【问题讨论】:
-
mysqli_query需要两个参数 - 其中一个是 db 连接,另一个是 sql 语句 -
我添加了 $connect 但我仍然遇到同样的错误。
标签: javascript php sql ajax database