안녕하세요, 데이터베이스 조회가 완료되었을 때 입력 한 값이 일치하지 않으면 다시 반향하는 방법을 찾으려고합니다.필드가없는 경우 에코하는 방법은 무엇입니까?
내가 조회를
은 ajax.js 할 요청 및 PHP를 실행하는 아약스를 사용하고 있습니다 :
function showResult(str)
{
if (str=="")
{
document.getElementById("description").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("description").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","getuser.php?voucher="+str,true);
xmlhttp.send(null);
}
및 getuser.php :
<?php
$q=$_GET["voucher"];
$con = mysql_connect('localhost', 'root', '');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("test", $con);
$sql="SELECT * FROM redemption WHERE voucher = '".$q."'";
$result = mysql_query($sql);
echo "<table>
<tr>
<th>Name</th>
<th>Product</th>
<th>Address</th>
<th>Status</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['product'] . "</td>";
echo "<td>" . $row['address'] ." ".$row['city'] ." ".$row['province'] ." ".$row['postal'] . "</td>";
echo "<td>" . $row['status'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
것은 내가 좋아하는 것이 무엇 그 사람이 유효하지 않은 바우처 번호를 입력하면 "바우처 번호를 찾을 수 없다"는 오류를 반환하고 싶습니다. "상환 됨"또는 "회수되지 않음"과 같은 상태를 저장하는 열도 있습니다. 바우처 번호가 있는지 여부와 이미 바우처 번호가 사용되었는지 여부를 어떻게 확인할 수 있습니까?
$sql="SELECT * FROM redemption WHERE voucher = '".$q."'" AND status = 'not redeemed'
과 같은 구문이어야하고 else 또는 case 문을 사용한다고 가정합니다.
미리 감사드립니다.
이 $ 작동하여 $ _GET – Pete