簡體   English   中英

PHP Ajax實時搜索僅適用於本地主機

[英]PHP Ajax live search only working on localhost

我正在導航欄上創建搜索表單,以在mysql表上搜索用戶。

我使用了我在網上找到的腳本,當我在localhost上使用它時,一切正常。 鍵入名稱的第一個字母后,我將立即獲得結果。

但是現在,我將網站放置在網絡服務器上,發生了以下情況:

  • 我寫了1到3個字母,但沒有任何反應。
  • 我寫了4/5字母並出現錯誤(致命錯誤:在第68行的/home/pg22933/public_html/jade/backend-search.php中調用未定義函數mysqli_stmt_get_result());
  • 我寫了幾乎一個用戶的全名,結果終於出現了。

這是我擁有所有代碼的文件:

<?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);
?>

我究竟做錯了什么?

http://php.net/manual/en/mysqli-stmt.get-result.php

它需要mysqlnd驅動程序,您需要在Web服務器上安裝它

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM