|
|
|
ทำฟอร์มสมัครสมาชิกโดยใช้ ajax แต่พอคลิก register แล้วไม่ไปใหนเลย |
|
|
|
|
|
|
|
ทำฟอร์มสมัครสมาชิกโดยใช้ ajax แต่พอคลิก register แล้วไม่ไปใหนเลยครับ
คือผมเอาฟอร์ม ajax จากที่นี่ไปลองแก้ใขดู พอเพิ่มฟิลล์กรอกรายระเอียดลงไปแล้วไปรัน มันนิ่งงเลยครับ ไม่เกิดอะไรขึ้นเลยครับ ช่วยดูหน่อยครับว่ามันติดตรงใหน
Code (PHP)
<?php
/*** By Weerachai Nukitram***/
/*** http://www.ThaiCreate.Com ***/
?>
<html>
<head>
<title>supplier registration page</title>
</head>
<script language="JavaScript">
var HttPRequest = false;
function doCallAjax() {
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 = 'sregis2.php';
var pmeters = "Status=" + encodeURI( document.getElementById("Status").value) +
"&sname=" + encodeURI( document.getElementById("sname").value) +
"&email=" + encodeURI( document.getElementById("email").value ) +
"&Password=" + encodeURI( document.getElementById("Password").value ) +
"&country=" + encodeURI( document.getElementById("country").value ) +
"&type=" + encodeURI( document.getElementById("type").value ) +
"&open=" + encodeURI( document.getElementById("open").value ) +
"&address=" + encodeURI( document.getElementById("address").value ) +
"&web=" + encodeURI( document.getElementById("web").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("mySpan").innerHTML = "Now is Loading...";
}
if(HttPRequest.readyState == 4) // Return Request
{
if(HttPRequest.responseText == 'Y')
{
window.location = 'sregis3.php';
}
else
{
document.getElementById("mySpan").innerHTML = HttPRequest.responseText;
}
}
}
}
</script>
<body>
<h1>Supplier Registration Form</h1>
<form name="frmMain">
<p><span id="mySpan"></span></p>
<table width="616" border="0" align="center">
<tr>
<th><div align="left">apply as </div></th>
<th width="236"><div align="left">
<label>
<select name="Status" size="1" id="Status">
<option value=""></option>
<option value="supplier">Advertistment</option>
<option value="career">Recruitment</option>
</select>
</label>
</div></th>
</tr>
<tr>
<th width="117">
<div align="left">company name </div></th>
<th><div align="left">
<input name="sname" type="text" class="input-text" id="sname" onFocus="clearValue(this,this.defaultValue)" onBlur="checkValue(this,this.defaultValue)" value="it will show on bigsearch preview" size="50">
</div></th>
</tr>
<tr>
<th><div align="left">Email</div></th>
<th><div align="left">
<input type="text" name="email" id="email" size="50">
</div></th>
</tr>
<tr>
<th><div align="left">Passowrd</div></th>
<th><div align="left"><input type="password" name="Password" id="Password" size="50">
</div></th>
</tr>
<tr>
<th><div align="left">country</div></th>
<th><div align="left"><select name="country" size="1">
<option value=""></option>
<option value="Algeria">Algeria</option>
<option value="Andorra">Andorra</option>
<option value="Antigua">Antigua & Barbuda</option>
</select></div></th>
</tr>
<tr>
<th><div align="left">type of business</div></th>
<th><div align="left"><select name="type" size="1" id="type">
<option value=""></option>
<option value=" Abstract Artists "> Abstract Artists </option>
<option value=" Access Equipment "> Access Equipment </option>
<option value=" Accessories "> Accessories </option>
</select></div></th>
</tr>
<tr>
<th><div align="left">open since</div></th>
<th><div align="left"><input name="open" type="text" id="open" maxlength="4">
</div></th>
</tr>
<tr>
<th><div align="left">company address</div></th>
<th><div align="left"><input name="address" type="text" id="address" size="50"></div></th>
</tr>
<tr>
<th><div align="left">company website</div></th>
<th><div align="left"><input name="web" type="text" id="web" value="http://" size="50">
</div></th>
</tr>
</table>
<div align="center"><br>
<input name="btnRegister" type="button" id="btnRegister" OnClick="JavaScript:doCallAjax();" value="Register">
</div>
</form>
</body>
</html>
อันนี้หน้าเก็บข้อมูลครับ
Code (PHP)
<?php
$strStatus = trim($_POST["Status"]);
$strsname = trim($_POST["sname"]);
$stremail = trim($_POST["email"]);
$strPassword = trim($_POST["Password"]);
$strcountry = trim($_POST["country"]);
$strtype = trim($_POST["type"]);
$stropen = trim($_POST["open"]);
$straddress = trim($_POST["address"]);
$strweb = trim($_POST["web"]);
//*** Check Status ***//
if(trim($strStatus) == "")
{
echo "<font color=red>**</font> Plase select [Status]";
exit();
}
//*** Check Company ***//
if(trim($strsname) == "")
{
echo "<font color=red>**</font> Plase select [sname]";
exit();
}
//*** Check email ***//
if(trim($stremail) == "")
{
echo "<font color=red>**</font> Plase input [email]";
exit();
}
//*** Check Name ***//
if(trim($strPassword) == "")
{
echo "<font color=red>**</font> Plase input [Password]";
exit();
}
//*** Check Status ***//
if(trim($strcountry) == "")
{
echo "<font color=red>**</font> Plase select [country]";
exit();
}
//*** Check Status ***//
if(trim($strtype) == "")
{
echo "<font color=red>**</font> Plase select [type]";
exit();
}
//*** Check Status ***//
if(trim($stropen) == "")
{
echo "<font color=red>**</font> Plase select [open]";
exit();
}
//*** Check Status ***//
if(trim($straddress) == "")
{
echo "<font color=red>**</font> Plase select [address]";
exit();
}
//*** Check Email ***//
if(trim($strweb) == "")
{
echo "<font color=red>**</font> Plase input [web]";
exit();
}
$objConnect = mysql_connect("localhost","db","pw") or die("Error Connect to Database");
$objDB = mysql_select_db("db_membersystem");
//*** Check Username (already exists) ***//
$strSQL = "SELECT * FROM supplier WHERE email = '".$stremail."' or sname = '".$strsname."' ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$objResult = mysql_fetch_array($objQuery);
if($objResult)
{
echo "<font color=red>**</font> please check your email or company name may already exists";
}
else
{
$strSQL = "INSERT INTO supplier";
$strSQL .="(Status,sname,email,Password,country,type,open,address,web) ";
$strSQL .="VALUES ";
$strSQL .="('".$strStatus."','".$strsname."','".$stremail."''".$strPassword."','".$strcountry."','".$strtype."','".$stropen."','".$straddress."','".$strweb."') ";
$objQuery = mysql_query($strSQL);
if($objQuery)
{
echo "Y"; // Finish Register Return "Y"
}
else
{
echo "<font color=red>**</font> Can not register";
}
}
mysql_close($objConnect);
?>
ตอนนี้ยังมึนอยู่เลยครับ ไปไม่ถูก
Tag : PHP, MySQL, Ajax
|
|
|
|
|
|
Date :
2011-02-15 11:59:51 |
By :
thanadol |
View :
1125 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลอง alert(HttPRequest.responseText) ดูนะ ว่ามันคืนค่ามาเป็นอะไร
|
|
|
|
|
Date :
2011-02-15 12:20:13 |
By :
ultrasiam |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|