用戶在文本框中鍵入someones用戶名並使用AJAX我自動向用戶建議單詞(用戶名)。MySQL查詢在本地主機和網站上的行爲不同
這是AJAX代碼在MySQL查詢是和打印出來:
<?php
include_once('connect.php');
$search_text = $_GET['search_text'];
$safe_text = mysql_real_escape_string($search_text);
if(strlen($search_text) > 0) {
$search_user = "SELECT * FROM accounts WHERE Name LIKE '$safe_text%' ORDER BY score DESC LIMIT 10";
$query = mysqli_query($con, $search_user) or die(mysql_error());
while ($row = mysqli_fetch_assoc($query)) {
$name = $row['Name'];
$id = $row['ID'];
$score = $row['Score'];
echo '<div class="well well-sm" style="margin-top:4px; margin-bottom: 0px;"><span class="glyphicon glyphicon-user" aria-hidden="true" style="margin-right: 5px;"></span><a href="/profile.php?id='.$id.'">'.$name.'</a><span class="badge" style="margin-left: 10px;">'.$score.' score</span></div><br>';
}
}
?>
這一切都在我的本地工作得很好。當我輸入'Joe'時,它給了我10行的名字,就像'Joe'一樣,並且按照分數排序(Joe的分數最高)。
問題是,當我在我的網絡服務器上使用它時,它只給出了10位得分最高的玩家。它不關心你輸入什麼,它從所有玩家中選擇(甚至與Joe沒有關係)。那麼是什麼原因造成的呢? 他們使用同一個數據庫兩者相同等
我不知道它是否導致問題,但你可以互換使用'mysql'和'mysqli'函數。你應該堅持'mysqli' – HPierce
'mysql_real_escape_string'返回'false'也許?由於@HPierce說的問題。 – AbraCadaver
你是完全正確的..從我的一個真正的錯字,它的意思是mysqli。現在它工作得很好。謝謝! –