我在导航栏上创建搜索表单以搜索mysql表上的用户。
我使用了我在网上找到的脚本,当我在localhost上使用它时,一切都很顺利。一旦我输入了名字的第一个字母,我就会立即得到结果。
但现在,我将网站放在网络服务器上,会发生以下情况:
这是我拥有所有代码的文件:
<?php include('headers.php'); ?>
<script type="text/javascript">
function updateentrada(value, id)
{
console.log(value, id);
if(value == 1)
{
$.ajax({
type: 'post',
url: 'loaddata.php',
data: {
idconvidado:id,
entrada: 0
},
success: function () {
location.reload();
}
});
}
else if (value == 0)
{
$.ajax({
type: 'post',
url: 'loaddata.php',
data: {
idconvidado:id,
entrada: 1
},
success: function () {
location.reload();
}
});
}
}
</script>
<?php
/* Attempt MySQL server connection. Assuming you are running MySQL
server with default setting (user 'root' with no password) */
$link = mysqli_connect("localhost", "root", "", "jade");
// Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
if(isset($_REQUEST['term'])){
// Prepare a select statement
$sql = "SELECT * FROM convidados WHERE nome_convidado LIKE ?";
if($stmt = mysqli_prepare($link, $sql)){
// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt, "s", $param_term);
// Set parameters
$param_term = $_REQUEST['term'] . '%';
// Attempt to execute the prepared statement
if(mysqli_stmt_execute($stmt)){
$result = mysqli_stmt_get_result($stmt);
// Check number of rows in the result set
if(mysqli_num_rows($result) > 0){
// Fetch result rows as an associative array
while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)){
$idconvidado = $row["id_convidado"];
$nome = $row["nome_convidado"];
$entrada = $row["entrada_convidado"];
if ($entrada == 1){
echo "<button value='". $entrada ."' name='". $idconvidado . "' onclick='updateentrada(this.value, this.name)' class='btnsearch'>" . $nome . " <i class='fa fa-check-circle-o check aria-hidden='true'></i></button>";
}
else if ($entrada == 0){
echo "<button value='". $entrada ."' name='". $idconvidado . "' onclick='updateentrada(this.value, this.name)' class='btnsearch '>" . $nome . " <i class='fa fa-circle-o check aria-hidden='true'></i></button>";
}
}
} else{
echo "<p>No matches found</p>";
}
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
}
// Close statement
mysqli_stmt_close($stmt);
}
// close connection
mysqli_close($link);
?>
我做错了什么?
答案 0 :(得分:1)
http://php.net/manual/en/mysqli-stmt.get-result.php
It requires the mysqlnd driver, you need to install it on your web server