|
|
|
ถามเรื่อง code check username ของ mr.win หน่อยครับ รบกวนด้วยครับ |
|
|
|
|
|
|
|
ลองเอา Code มาดูครับ
|
|
|
|
|
Date :
2011-05-26 13:47:33 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
มีการรับค่ามาหรือเปล่าอะครับ
|
|
|
|
|
Date :
2011-05-26 13:49:48 |
By :
treza |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (JavaScript)
var HttPRequest = false;
function ChkUser() {
HttPRequest = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
HttPRequest = new XMLHttpRequest();
if (HttPRequest.overrideMimeType) {
HttPRequest.overrideMimeType('text/html');
}
} else if (window.ActiveXObject) { // IE
try {
HttPRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
HttPRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!HttPRequest) {
alert('Cannot create XMLHTTP instance');
return false;
}
var url = 'Cuser.php';
var pmeters = "tUsername=" + encodeURIComponent( document.getElementById("Username").value);
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) // Loading Request
{
document.getElementById("vuser").innerHTML = "<img src='images/loader.gif' align='absmiddle'> Please Wait..";
}
if(HttPRequest.readyState == 4) // Return Request
{
//alert(HttPRequest.responseText);
if(HttPRequest.responseText == 'Y')
{
window.location = 'Register_OK.php';
}
else
{
document.getElementById("vuser").innerHTML = HttPRequest.responseText;
}
}
}
}
Code (PHP)
<?php
//session_start();
include("ConDB.php");
$strUsername = trim($_POST["tUsername"]);
$strSQL = "SELECT * FROM login_user WHERE User_N = '".$strUsername."' ";
$objQuery = mysql_query($strSQL);
$objResult = mysql_fetch_array($objQuery);
if($objResult)
{
echo "Cannot use ID";
//echo "<img src='images/false.png'>";
}
else
{
echo "Can be Used";
//echo "<img src='images/true.png'>";
}
mysql_close();
?>
|
ประวัติการแก้ไข 2011-05-26 13:56:23 2011-05-26 13:57:34
|
|
|
|
Date :
2011-05-26 13:55:09 |
By :
kamuro |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code มีแค่นี้เหรอครับ
|
|
|
|
|
Date :
2011-05-26 14:08:53 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ผมแยก Function ไว้อะครับ
Function ต่อจาก ChkUser ก็เป็น Function Validate form ทั่วไปอะครับ
อีกอันก็เป็น Form ทั่วไปที่ใช้ call function นี้อะครับ
ส่วนหน้าที่อยากให้ไปต่อหลังจาก check username แล้วก็เป็นหน้าคำสั้ง sql ลง Base อะครับ
|
ประวัติการแก้ไข 2011-05-26 14:27:32
|
|
|
|
Date :
2011-05-26 14:19:47 |
By :
kamuro |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (HTML)
<form id="formreg" name="formreg" method="post" onsubmit="return Validate_Register()" >
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="10" align="right" scope="row"> </td>
<td> </td>
</tr>
<tr>
<td width="30%" height="30" align="right" class="Style-Font-6" scope="row">Username : </td>
<td width="70%" align="left"><label for="Username"></label>
<input name="Username" type="text" id="Username" size="20" maxlength="20"
onchange="javascript:ChkUser()" /> <span class="Style-Font-3" id="vuser"></span></td>
</tr>
<tr>
<td height="30" align="right" class="Style-Font-6" scope="row">Password : </td>
<td align="left"><label for="Password1"> </label>
<input name="Password1" type="password" id="Password1" size="21" maxlength="21" /></td>
</tr>
<tr>
<td height="30" align="right" class="Style-Font-6" scope="row">Confirm Password : </td>
<td align="left"><label for="Password2"></label>
<input name="Password2" type="password" id="Password2" size="21" maxlength="21" /></td>
</tr>
<tr>
<td align="right" class="Style-Font-6" scope="row"> </td>
<td align="left"> </td>
</tr>
<tr>
<td height="30" align="right" class="Style-Font-6" scope="row">Name : </td>
<td align="left"><label for="Name"></label>
<input name="Name" type="text" id="Name" size="25" maxlength="25" /></td>
</tr>
<tr>
<td height="30" align="right" class="Style-Font-6" scope="row">Last name : </td>
<td align="left"><label for="L_Name"></label>
<input name="L_Name" type="text" id="L_Name" size="25" maxlength="25" /></td>
</tr>
<tr>
<td height="30" align="right" class="Style-Font-6" scope="row">Gender : </td>
<td align="left" class="Style-Font-6">
<input type="radio" name="Gender" id="Male" value="Male" checked="checked" />Male
<input type="radio" name="Gender" id="Female" value="Female" />Female
</td>
</tr>
<tr>
<td height="91" align="right" class="Style-Font-6" scope="row">Address : </td>
<td align="left">
<textarea name="Address" id="Address" cols="30" rows="5"></textarea></td>
</tr>
<tr>
<td height="30" align="right" class="Style-Font-6" scope="row">Country : </td>
<td align="left"><label for="Country"></label>
<input name="Country" type="text" id="Country" size="20" maxlength="20" /></td>
</tr>
<tr>
<td height="30" align="right" class="Style-Font-6" scope="row">Zip Code : </td>
<td align="left"><label for="Zip_Code"></label>
<input name="Zip_Code" type="text" id="Zip_Code" size="15" maxlength="15"
onkeypress="return numbersonly(this,value)" /></td>
</tr>
<tr>
<td height="30" align="right" class="Style-Font-6" scope="row">Telephone : </td>
<td align="left"><label for="Tel"></label>
<input name="Tel" type="text" id="Tel" size="20" maxlength="20"
onkeypress="return numbersonly(this,value)" />
<span class="Style-Font-3">Ex.+66021234567</span></td>
</tr>
<tr>
<td height="30" align="right" class="Style-Font-6" scope="row">Mobile Phone : </td>
<td align="left"><label for="Mtel"></label>
<input name="Mtel" type="text" id="Mtel" size="20" maxlength="20"
onkeypress="return numbersonly(this,value)" />
<span class="Style-Font-3">Ex.+660811234567</span></td>
</tr>
<tr>
<td height="30" align="right" class="Style-Font-6" scope="row">E-mail : </td>
<td align="left"><label for="E_Mail"></label>
<input name="E_Mail" type="text" id="E_Mail" size="40" maxlength="40" /></td>
</tr>
<tr>
<td align="right" scope="row"> </td>
<td><input type="hidden" name="ChkS" id="ChkS" value="0" /></td>
</tr>
<tr>
<td height="30" align="right" scope="row"> </td>
<td><table width="174" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="88" align="center" scope="row">
<input type="submit" name="Register" id="Register" value="Register" /></td>
<td width="86" align="center" scope="row">
<input type="reset" name="Reset" id="Reset" value="Reset" /></td>
</tr>
</table></td>
</tr>
<tr>
<td height="19" align="right" scope="row"> </td>
<td> </td>
</tr>
</table>
</form>
|
|
|
|
|
Date :
2011-05-26 14:28:36 |
By :
kamuro |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
นี้ Function JS ที่ใช้ Call ครับ ผมงงว่า Function Validate ผมมันก็ไม่หน้าไปกวนนะครับ ลองดูหลายทีแล้วมันไม่ไปเลยครับ
Code (JavaScript)
var HttPRequest = false;
function ChkUser() {
HttPRequest = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
HttPRequest = new XMLHttpRequest();
if (HttPRequest.overrideMimeType) {
HttPRequest.overrideMimeType('text/html');
}
} else if (window.ActiveXObject) { // IE
try {
HttPRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
HttPRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!HttPRequest) {
alert('Cannot create XMLHTTP instance');
return false;
}
var url = 'Cuser.php';
var pmeters = "tUsername=" + encodeURIComponent( document.formreg.Username.value);
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) // Loading Request
{
document.getElementById("vuser").innerHTML = "<img src='images/loader.gif' align='absmiddle'> Please Wait..";
}
if(HttPRequest.readyState == 4) // Return Request
{
//alert(HttPRequest.responseText);
if(HttPRequest.responseText == 'Y')
{
window.location = 'Register_OK.php';
}
else
{
document.getElementById("vuser").innerHTML = HttPRequest.responseText;
}
}
}
}
function Validate_Register()
{
var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
var frmg = document.formreg;
var address = frmg.E_Mail.value;
if(frmg.Username.value == "")
{
alert("Please Input Username");
frmg.Username.focus();
return false;
}
if(frmg.Password1.value.length < 6)
{
alert("Password Minimum is 6 Character");
frmg.Password1.focus();
return false;
}
if(frmg.Password1.value !== frmg.Password2.value)
{
alert("Password Confirm not Match");
frmg.Password2.focus();
return false;
}
if(frmg.Name.value == "")
{
alert("Please Input First Name");
frmg.Name.focus();
return false;
}
if(frmg.L_Name.value == "")
{
alert("Please Input Last Name");
frmg.L_Name.focus();
return false;
}
if(frmg.Address.value == "")
{
alert("Please Input Address");
frmg.Address.focus();
return false;
}
if(frmg.Tel.value == "")
{
alert("Please Input Telephone");
frmg.Tel.focus();
return false;
}
if(frmg.Mtel.value == "")
{
alert("Please Input Mobile Phone");
frmg.Mtel.focus();
return false;
}
if(frmg.Country.value == "")
{
alert("Please Input Country");
frmg.Country.focus();
return false;
}
if(frmg.Zip_Code.value == "")
{
alert("Please Input Zip Code");
frmg.Zip_Code.focus();
return false;
}
if(frmg.Mtel.value == "")
{
alert("Please Input Mobile Phone");
frmg.Mtel.focus();
return false;
}
if(frmg.E_Mail.value == "")
{
alert("Please Input E_Mail");
frmg.E_Mail.focus();
return false;
}
if(reg.test(address) == false)
{
alert("Invalid Email Address");
frmg.E_Mail.focus();
return false;
}
if(frmg.txtCaptcha.value == "")
{
alert("Please Input Security Code");
frmg.txtCaptcha.focus();
return false;
}
if(frmg.box.checked == false)
{
alert("Please Agree Rule");
frmg.box.focus();
return false;
}
}
|
|
|
|
|
Date :
2011-05-26 14:41:34 |
By :
kamuro |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ผมลองเอา Code ของ พี่วิน ไปลอง เทส สดๆ แล้ว มันก็ยังไม่ไปหน้าที่จะให้ไปหลังจาก Chk แล้วอยู่ดีครับ
รบกวนด้วยครับ
|
|
|
|
|
Date :
2011-05-26 14:51:41 |
By :
kamuro |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
คุณลองไล่ alert('Debug'); ตรง function ที่มีปัญหาครับ ว่ามันหลุดตรงไหน และก็อย่าลืมใส่ return true; ในบรรทัดสุดท้ายด้วยครับ
|
|
|
|
|
Date :
2011-05-26 15:19:50 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|