|
|
|
รบกวนผู้รู้ครับ ... คือผม load file สมัครสมาชิกจากที่นี้ไปลงเรียบร้อยใช้ได้ดีครับแต่ต้องการเพิ่มข้อมูลอีกอ่ะครั |
|
|
|
|
|
|
|
คือผม load file สมัครสมาชิกจากที่นี้ไปลงเรียบร้อยใช้ได้ดีครับแต่ต้องการเพิ่มข้อมูลอีกอ่ะครับ คือข้อมูลเก่ามันมีแค่ 4 อัน Username,Password,Name,Email อยากเพิ่มอีก 2 อัน คือ Dept กับ Phone ลองยังงัยมันก็ไม่วิ่งเข้า Database
*Load มา 3 file อ่ะครับ
fileที่ 1 ชื่อ ajaxphpregister1.php
Code (PHP)
<?php
/*** By Weerachai Nukitram ***/
/*** http://www.ThaiCreate.Com ***/
?>
<html>
<head>
<title>ThaiCreate.Com Ajax Tutorial</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 = 'AjaxPHPRegister2.php';
var pmeters = "tUsername=" + encodeURI( document.getElementById("txtUsername").value) +
"&tPassword=" + encodeURI( document.getElementById("txtPassword").value ) +
"&tName=" + encodeURI( document.getElementById("txtName").value ) +
"&tEmail=" + encodeURI( document.getElementById("txtEmail").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 = 'AjaxPHPRegister3.php';
}
else
{
document.getElementById("mySpan").innerHTML = HttPRequest.responseText;
}
}
}
}
</script>
<body>
<h1>Register Form</h1>
<form name="frmMain">
<span id="mySpan"></span>
<table width="274" border="1">
<tr>
<th width="117">
<div align="left">Username</div></th>
<th><input type="text" name="txtUsername" id="txtUsername" size="20"></th>
</tr>
<tr>
<th width="117">
<div align="left">Password</div></th>
<th><input type="password" name="txtPassword" id="txtPassword" size="20"></th>
</tr>
<tr>
<th width="117">
<div align="left">Name</div></th>
<th><input type="text" name="txtName" id="txtName" size="20"></th>
</tr>
<tr>
<th width="117">
<div align="left">Email</div></th>
<th width="236"><input type="text" name="txtEmail" id="txtEmail" size="20"></th>
</tr>
</table>
<br>
<input name="btnRegister" type="button" id="btnRegister" OnClick="JavaScript:doCallAjax();" value="Register">
</form>
</body>
</html>
[font=Verdana]fileที่ 2 ชื่อ ajaxphpregister2.php[/font]
Code (PHP)
<?php
/*** By Weerachai Nukitram ***/
/*** http://www.ThaiCreate.Com ***/
$strUsername = trim($_POST["tUsername"]);
$strPassword = trim($_POST["tPassword"]);
$strName = trim($_POST["tName"]);
$strEmail = trim($_POST["tEmail"]);
//*** Check Username ***//
if(trim($strUsername) == "")
{
echo "<font color=red>**</font> Please input [Username]";
exit();
}
//*** Check Password ***//
if(trim($strPassword) == "")
{
echo "<font color=red>**</font> Please input [Password]";
exit();
}
//*** Check Name ***//
if(trim($strName) == "")
{
echo "<font color=red>**</font> Please input [Name]";
exit();
}
//*** Check Email ***//
if(trim($strEmail) == "")
{
echo "<font color=red>**</font> Please input [Email]";
exit();
}
$objConnect = mysql_connect("localhost","root","123") or die("Error Connect to Database");
$objDB = mysql_select_db("mydatabase");
//*** Check Username (already exists) ***//
$strSQL = "SELECT * FROM account WHERE Username = '".$strUsername."' ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$objResult = mysql_fetch_array($objQuery);
if($objResult)
{
echo "<font color=red>**</font> Username [$strUsername] already exists";
}
else
{
$strSQL = "INSERT INTO account ";
$strSQL .="(Username,Password,Name,Email) ";
$strSQL .="VALUES ";
$strSQL .="('".$strUsername."','".$strPassword."' ";
$strSQL .=",'".$strName."','".$strEmail."') ";
$objQuery = mysql_query($strSQL);
if($objQuery)
{
echo "Y"; // Finish Register Return "Y"
}
else
{
echo "<font color=red>**</font> Can not register";
}
}
mysql_close($objConnect);
?>
fileที่ 1 ชื่อ ajaxphpregister3.php
Code (PHP)
<?php
/*** By Weerachai Nukitram ***/
/*** http://www.ThaiCreate.Com ***/
?>
<html>
<head>
<title>ThaiCreate.Com Ajax Tutorial</title>
</head>
<body>
<h1>Register Finish</h1>
</body>
</html>
Tag : - - - -
|
|
|
|
|
|
Date :
2010-01-23 12:36:46 |
By :
ninho6529 |
View :
856 |
Reply :
7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลืมบอกตอนนี้ทำอยู่คือมันวิ่งเข้า 4 อัน ที่ให้มา และได้ทำ field ใน database เพิ่มรอใว้แล้วสำหรับอีก 2 field ที่ต้องการ
|
|
|
|
|
Date :
2010-01-23 12:39:02 |
By :
ninho6529 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ตามนี้นะครับ โค๊ดแรก
<?php
/*** By Weerachai Nukitram ***/
/*** http://www.ThaiCreate.Com ***/
?>
<html>
<head>
<title>ThaiCreate.Com Ajax Tutorial</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 = 'AjaxPHPRegister2.php';
var pmeters = "tUsername=" + encodeURI( document.getElementById("txtUsername").value) +
"&tPassword=" + encodeURI( document.getElementById("txtPassword").value ) +
"&tName=" + encodeURI( document.getElementById("txtName").value ) +
"&tEmail=" + encodeURI( document.getElementById("txtEmail").value )+
"&tEmail=" + encodeURI( document.getElementById("txtDept").value )+
"&tEmail=" + encodeURI( document.getElementById("txtPhone").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 = 'AjaxPHPRegister3.php';
}
else
{
document.getElementById("mySpan").innerHTML = HttPRequest.responseText;
}
}
}
}
</script>
<body>
<h1>Register Form</h1>
<form name="frmMain">
<span id="mySpan"></span>
<table width="274" border="1">
<tr>
<th width="117">
<div align="left">Username</div></th>
<th><input type="text" name="txtUsername" id="txtUsername" size="20"></th>
</tr>
<tr>
<th width="117">
<div align="left">Password</div></th>
<th><input type="password" name="txtPassword" id="txtPassword" size="20"></th>
</tr>
<tr>
<th width="117">
<div align="left">Name</div></th>
<th><input type="text" name="txtName" id="txtName" size="20"></th>
</tr>
<tr>
<th width="117">
<div align="left">Email</div></th>
<th width="236"><input type="text" name="txtEmail" id="txtEmail" size="20"></th>
</tr>
<tr>
<th width="117">
<div align="left">Dept</div></th>
<th width="236"><input type="text" name="txtDept" id="txtDept" size="20"></th>
</tr>
<tr>
<th width="117">
<div align="left">Phone</div></th>
<th width="236"><input type="text" name="txtPhone" id="txtPhone" size="20"></th>
</tr>
</table>
<br>
<input name="btnRegister" type="button" id="btnRegister" OnClick="JavaScript:doCallAjax();" value="Register">
</form>
</body>
</html>
|
|
|
|
|
Date :
2010-01-23 18:26:24 |
By :
Dragons_first |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
โค๊ดอันที่สองครับ
<?php
/*** By Weerachai Nukitram ***/
/*** http://www.ThaiCreate.Com ***/
$strUsername = trim($_POST["tUsername"]);
$strPassword = trim($_POST["tPassword"]);
$strName = trim($_POST["tName"]);
$strEmail = trim($_POST["tEmail"]);
$strDept = trim($_POST["tDept"]);
$strPhone = trim($_POST["tPhone"]);
//*** Check Username ***//
if(trim($strUsername) == "")
{
echo "<font color=red>**</font> Please input [Username]";
exit();
}
//*** Check Password ***//
if(trim($strPassword) == "")
{
echo "<font color=red>**</font> Please input [Password]";
exit();
}
//*** Check Name ***//
if(trim($strName) == "")
{
echo "<font color=red>**</font> Please input [Name]";
exit();
}
//*** Check Email ***//
if(trim($strEmail) == "")
{
echo "<font color=red>**</font> Please input [Email]";
exit();
}
//*** Check Dept ***//
if(trim($strDept) =="")
{
echo "<font color=red>**</font> Please input [Dept]";
exit();
}
//*** Check Phone ***//
if(trim($strPhone) =="")
{
echo "<font color=red>**</font> Please input [Phone]";
exit();
}
$objConnect = mysql_connect("localhost","root","123") or die("Error Connect to Database");
$objDB = mysql_select_db("mydatabase");
//*** Check Username (already exists) ***//
$strSQL = "SELECT * FROM account WHERE Username = '".$strUsername."' ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$objResult = mysql_fetch_array($objQuery);
if($objResult)
{
echo "<font color=red>**</font> Username [$strUsername] already exists";
}
else
{
$strSQL = "INSERT INTO account ";
$strSQL .="(Username,Password,Name,Email,Dept,Phone) ";
$strSQL .="VALUES ";
$strSQL .="('".$strUsername."','".$strPassword."' ";
$strSQL .=",'".$strName."','".$strEmail."') ";
$strSQL .=",'".$strDept."','".$strPhone."') ";
$objQuery = mysql_query($strSQL);
if($objQuery)
{
echo "Y"; // Finish Register Return "Y"
}
else
{
echo "<font color=red>**</font> Can not register";
}
}
mysql_close($objConnect);
?>
อันที่สาม ไม่ต้องครับ เพราะว่าไม่เกี่ยวกัน
|
|
|
|
|
Date :
2010-01-23 18:32:33 |
By :
Dragons_first |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณ คุณDragons_first ครับ
แต่มันก็ไม่สำเร็จอ่ะครับคือพอผมลองกรอกข้อมูลครบทั้ง 6 ช่องมันขึ้นว่า Please insert Dept ทั้งที่เรากรอกครบแล้ว และพอ click เพื่อจะRegister มันก็ค้างอยู่หน้าเดิมไม่ไปที่หน้า 3 อ่ะครับ
รบกวนอีกทีน่ะครับ
หรือว่าผมทำอะไรผิด ผม copy ทั้งหมดแล้วมาวางใน file ผมเลยน่ะครับ
|
|
|
|
|
Date :
2010-01-23 21:00:11 |
By :
ninho6529 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ไม่น่ามีปัญหานะครับ แล้วตั้งชื่อในฐานข้อมูลเหมือนกับในไฟล์รึป่าวล่ะ ถ้าถูกอีกเด๋วจะดูโค๊ดให้อีกรอบนะครับ
|
|
|
|
|
Date :
2010-01-24 00:26:06 |
By :
Dragons_first |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
อะครับแก้ให้แล้วลองดูอีกที ก๊อปปี้ไฟล์นี้ไปนะครับ
<?php
/*** By Weerachai Nukitram ***/
/*** http://www.ThaiCreate.Com ***/
?>
<html>
<head>
<title>ThaiCreate.Com Ajax Tutorial</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 = 'AjaxPHPRegister2.php';
var pmeters = "tUsername=" + encodeURI( document.getElementById("txtUsername").value) +
"&tPassword=" + encodeURI( document.getElementById("txtPassword").value ) +
"&tName=" + encodeURI( document.getElementById("txtName").value ) +
"&tEmail=" + encodeURI( document.getElementById("txtEmail").value )+
"&tDept=" + encodeURI( document.getElementById("txtDept").value )+
"&tPhone=" + encodeURI( document.getElementById("txtPhone").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 = 'AjaxPHPRegister3.php';
}
else
{
document.getElementById("mySpan").innerHTML = HttPRequest.responseText;
}
}
}
}
</script>
<body>
<h1>Register Form</h1>
<form name="frmMain">
<span id="mySpan"></span>
<table width="274" border="1">
<tr>
<th width="117">
<div align="left">Username</div></th>
<th><input type="text" name="txtUsername" id="txtUsername" size="20"></th>
</tr>
<tr>
<th width="117">
<div align="left">Password</div></th>
<th><input type="password" name="txtPassword" id="txtPassword" size="20"></th>
</tr>
<tr>
<th width="117">
<div align="left">Name</div></th>
<th><input type="text" name="txtName" id="txtName" size="20"></th>
</tr>
<tr>
<th width="117">
<div align="left">Email</div></th>
<th width="236"><input type="text" name="txtEmail" id="txtEmail" size="20"></th>
</tr>
<tr>
<th width="117">
<div align="left">Dept</div></th>
<th width="236"><input type="text" name="txtDept" id="txtDept" size="20"></th>
</tr>
<tr>
<th width="117">
<div align="left">Phone</div></th>
<th width="236"><input type="text" name="txtPhone" id="txtPhone" size="20"></th>
</tr>
</table>
<br>
<input name="btnRegister" type="button" id="btnRegister" OnClick="JavaScript:doCallAjax();" value="Register">
</form>
</body>
</html>
|
|
|
|
|
Date :
2010-01-24 00:28:15 |
By :
Dragons_first |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ได้แล้วครับ ขอบคุณ คุณDragons_first ครับผม
|
|
|
|
|
Date :
2010-01-24 15:34:47 |
By :
ninho6529 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|