我目前正在學習AJAX,並且遇到了此錯誤,其中未顯示MySQL查詢的結果。嘗試打印出MySQL時出現AJAX問題查詢
下面的代碼片斷是JavaScript的:
<script type="text/javascript">
function showCustomers()
{
var zip = document.getElementById('zipcode').value;
var st = document.getElementById('stname').value;
if ((zip=="")&&(st=="")){
document.getElementById("showCustResults").innerHTML="";
return;
}
mlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200){
document.getElementById("showCustResults").innerHTML=xmlhttp.responseText;
}
}
var querystring = "?zip" + zip + "&st" + st ;
xmlhttp.open("POST","findCustomers.php" + querystring, true);
xmlhttp.send();
}
以下是其中信息被從拉的形式:被拉動
<form id="search_customers" class="appnitro" method="post" action="">
<ul>
<li id="li_2" >
<label class="description" for="zipcode">Zip Code </label>
<div><input id="zipcode" name="zip_code" class="element text small" type="text" maxlength="10" value=""/> </div>
<p class="guidelines" id="guide_2"><small>Please enter a Zip Code</small></p>
</li>
<li id="li_1" >
<label class="description" for="stname">Street Name </label>
<div><input id="stname" name="st_name" class="element text medium" type="text" maxlength="50" value=""/></div>
<p class="guidelines" id="guide_1"><small>Please Enter the Street Name</small></p>
</li>
<li class="buttons">
<input id="findCust" class="button_text" onclick="showCustomers()" type="submit" name="find"/>
</li>
</ul>
</form>
<div id="showCustResults"><!-- Eventually search results will appear here --></div>
而PHP鱈魚是如下:
<?php
include 'functions.php'; #Library that holds all the functions
#Sanitizing strings for SQL entry
$zip = mysqli_real_escape_string($db, $_POST['zip']);
$st = mysqli_real_escape_string($db, $_POST['st']);
$db = db_connect(); #Connecting to the database
#Querying the database to find any matches
#ALSO: We might need to add another column to
$sql = "SELECT CustomerName, ServiceAddress, BillingAddress FROM enrollment_users WHERE UserName = '$username' AND Password = '$password'";
$res = mysqli_query($db, $sql);
#Creating the table to shoot out the information
#First the header...
echo "<table border='1'>";
echo " <tr>";
echo " <th>Customer</th>";
echo " <th>Address 1</th>";
echo " <th>Address 2</th>";
echo " <th>Status</th>";
echo " </tr>";
#Now the actualy information
while($row = mysqli_fetch_assoc($res)){
echo " <tr>";
echo " <td>" . $row['CustomerName'] . "</td>";
echo " <td>" . $row['ServiceAddress'] . "</td>";
echo " <td>" . $row['BillingAddress'] . "</td>";
echo " <td></td>";
}
echo"</table>";
db_close($db); #Closing the database
?>
我一直在試圖找出過去一天無濟於事。希望有人能看到我不能。
提前感謝。
如果我缺少任何信息,也請隨時告訴我。 :D – 2013-02-26 20:32:41
你能解釋一下你的代碼不工作嗎? – sdespont 2013-02-26 20:34:58
你不應該存儲明文密碼。用bcrypt或類似的東西對其進行哈希處理。 – Blender 2013-02-26 20:38:08