嘗試編輯我在W3學校中找到的腳本。使用Javascript的PHP表單
編輯: 我想要一個搜索文本框。我可以在其中輸入數據,它會觸發PHP腳本並返回值,而無需重新加載主頁。因此,當我輸入「404040」並單擊搜索按鈕時,它應該執行adminsearchvip.php?q = 404040 然後返回值而不重新編碼主頁。 編輯結束。
原始腳本是一個下拉菜單,但我想要一個textboxt insted。
我不確定發送「提交」按鈕的代碼是否正確。
第一個文件searchvip.php
<html>
<head>
<script>
function showUser()
{
if (str=="")
{
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","adminsearchvip.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<form>
<label for="Number"></label>
<input type="text" name="Number" id="Numbers" value="">
<input type='button' onclick='showUser(Numbers.value)' value='Search' />
</form>
<br>
<div id="txtHint"><b>Person info will be listed here.</b></div>
</body>
</html>
和腳本它自我。
adminsearchvip.php
<?php
$q = intval($_GET['q']);
$con = mysqli_connect('localhost','xxxxxx','xxxxx','jossan');
if (!$con)
{
die('Could not connect: ' . mysqli_error($con));
}
mysqli_select_db($con,"jossan");
$sql="SELECT * FROM vip_stat WHERE code = '".$q."'";
$result = mysqli_query($con,$sql);
echo "<table border='1'>
<tr>
<th>Number</th>
<th>Bought Date</th>
<th>Type</th>
<th>Price</th>
<th>Used</th>
<th>Activation Date</th>
<th>Username</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['number'] . "</td>";
echo "<td>" . $row['time'] . "</td>";
echo "<td>" . $row['type'] . "</td>";
echo "<td>" . $row['Price'] . "</td>";
echo "<td>" . $row['used'] . "</td>";
echo "<td>" . $row['utime'] . "</td>";
echo "<td>" . $row['username'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
我已經測試了,還有我的網頁瀏覽器的www.homepage.com/adminsearchvip.php?q=9494943和工作,我得到了正確的respons。所以腳本似乎工作。但搜索頁面甚至沒有顯示任何內容。
如果「魔獸學堂」你主持我知道意思是w3schools,你真的不應該讀他們發表的任何東西。要找出原因,請查看http://www.w3fools.com。 – rid