จากโค้ดด้าานล่างนี้นี้เป็นการเช็ค user ซ้ำอย่างเดี่ยว ด้วย ajax
แต่ผมอยากทราบว่าจะเช็คทั้ง user และ email อย่างไรครับ ผมลองใส่ค่าparameter ตัวสีแดงในโค้ด ก็ยังไม่ได้ครับ
ขอคำแนะนำด้วยนะครับ
Code
<html>
<head>
</head>
<script language="JavaScript">
function doCallAjax()
{
if(window.XMLHttpRequest)
{
HttPRequest = new XMLHttpRequest();
if (HttPRequest.overrideMimeType)
{
HttPRequest.overrideMimeType('text/html');
}
}
else if (!HttPRequest)
{
alert('Cannot create XMLHTTP instance');
return false;
}
var url='CheckTrue.php';
var pmeters="UserName=" + encodeURI( document.getElementById("UserName").value);
[font=Verdana]var pmeters="Email=" + encodeURI( document.getElementById("Email").value);[/font]
HttPRequest.open('POST',url,true);
HttPRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
HttPRequest.setRequestHeader("Content-length", pmeters.length);
HttPRequest.setRequestHeader("Connection", "close");
HttPRequest.send(pmeters);
HttPRequest.onreadystatechange = function()
{
if(HttPRequest.readyState == 3)
{
document.getElementById("mySpan").innerHTML = "..";
}
else
{
document.getElementById("mySpan").innerHTML = HttPRequest.responseText;
}
}
}
</script>
<body>
<div id="head">
<form action="AddData.php" method="get">
<table width="466" align="center" border="1">
<tr>
<th width="155">UserName :</th>
<th width="295"><div align="left">
<input name="UserName" type="text" size="25" id="UserName" onChange="JavaScript:doCallAjax();">
<span id="mySpan"></span></div>
</th>
</tr>
<tr>
<th width="155">FirstName :</th>
<th width="295"><div align="left"><input name="FirstName" type="text" size="25"></div>
</th>
</tr>
<tr>
<th width="155">LastName :</th>
<th width="295"><div align="left"><input name="LastName" type="text" size="25"></div>
</th>
</tr>
<tr>
<th width="155">Password :</th>
<th width="295"><div align="left"><input name="Password" type="password" size="25"></div>
</th>
</tr>
<tr>
<th width="155">Telephone :</th>
<th width="295"><div align="left"><input name="Telephone" type="text" size="25"></div>
</th>
</tr>
<tr>
<th width="155">Email :</th>
<th width="295"><div align="left">
<input name="Email" type="text" size="25" id="Email" ></div>
</th>
</tr>
<tr>
<th width="155">Address :</th>
<th width="295"><div align="left"><textarea name="Address" cols="18" rows="2"></textarea></div>
</th>
</tr>
<tr>
<th width="155"> </th>
<th width="295"><div align="left"><input name="Confirm" type="submit" value="Confirm">
<input name="Reset" type="reset" value="Reset"></div>
</th>
</tr>
</table>
</form>
</div>
</body>
</html>
------------------------------------------------------------------
Code
<?php
$host="127.0.0.1";
$user="root";
$passwd="1234";
$dbname="custom-guitar";
mysql_connect($host,$user,$passwd) or die ("ติดต่อ host ไม่ได้");
mysql_select_db($dbname) or die ("!Database is not");
$sql="select * from Member where UserName='$UserName' OR Email='$Email' ";
$dbquery=mysql_db_query($dbname,$sql);
$result = mysql_fetch_array($dbquery);
if($result)
{
echo "Repeatedly !";
}
else
{
echo "Available.";
}
mysql_close();
?>
Tag : PHP