 |
|
Code (JavaScript)
หน้าที่ 1
<script>
var req;
function check(){
if(window.XMLHttpRequest)
{
req = new XMLHttpRequest();
}
else if(window.ActiveXobject)
{
req = new ActiveXObject("Mocrosoft.XMLHTTP");
}
else
{alert('Browser not support');
return false;
}
var txtUsername1=document.myForm.txtUsername.value;
var pw1=document.myForm.pw.value;
var name1=document.myForm.name.value;
if(document.myForm.rd1.checked==true){
var sex1="ชาย";}else{sex1="";}
if(document.myForm.rd2.checked==true){
var sex2="หญิง";}else{sex2="";}
var new_Date1=document.myForm.new_Date.value;
var new_Month1=document.myForm.new_Month.value;
var new_Years1=document.myForm.new_Years.value;
var phone1=document.myForm.phone.value;
var txtAge1=document.myForm.txtAge.value;
var occupation1=document.myForm.occupation.value;
var status1=document.myForm.status.value;
var province1=document.myForm.province.value;
var amphur1=document.myForm.amphur.value;
var district1=document.myForm.district.value;
var id_province1=document.myForm.id_province.value;
var str=Math.random();
var querystr="chk_user_ajax.php?pop="+str+"&txtUsername="+txtUsername1+"&pw="+pw1+"&name="+name1+"&sex="+sex1+sex2+"&new_Date="+new_Date1;
var querystr1=querystr+"&new_Month="+new_Month1+"&new_Years="+new_Years1+"&phone="+phone1+"&txtAge="+txtAge1+"&occupation="+occupation1+"&status="+status1+"&province="+province1+"&hur="+amphur1+"&district="+district1+"&id_province="+id_province1;
req.open("GET",querystr1,true);
req.send(null);
req.onreadystatechange=function(){
if(req.readyState==4)
{
document.getElementById('pan1').innerHTML=req.responseText;
}
else
{
document.getElementById('pan1').innerHTML="<img src=image/indicator>";
}
}
}
function hidden(){
document.getElementById('pan2').style.display='none';
}
</script>
หน้าที่ 2 chk_user_ajax.php ครับ
Code (PHP)
<?
header("content-type: text/html; charset=windows-874");
$txtUsername=$_GET['txtUsername'];
$user=$_COOKIE['user'];
$pw =$_GET['pw'];
$pass_md5 = md5($pw);
$name =$_GET['name'];
$email =$_GET['email'];
$address =$_GET['address'];
$sex =$_GET['sex'];
$txtAge =$_GET['txtAge'];
$citizen =$_GET['citizen'];
$new_Date=$_GET['new_Date'];
$new_Month=$_GET['new_Month'];
$new_Years=$_GET['new_Years'];
$phone =$_GET['phone'];
$occupation =$_GET['occupation'];
$status =$_GET['status'];
$province=$_GET['province'];
$amphur=$_GET['amphur'];
$district=$_GET['district'];
$id_province=$_GET['id_province'];
include('config.inc.php');
$sql="select*from userinfo where username='$txtUsername' ";
$result = mysql_query($sql);
$num_rows=mysql_num_rows($result);
if($num_rows==1)
{
print"<table border=0 bgcolor=red width=98% >";
print"<tr bgcolor=red>";
print"<td bgcolor=red align=center><B>Username ซ้ำครับ.</B></td>";
print"</tr>";
print"</table>";
print"<br>";
}else{
$age="$new_Date-$new_Month-$new_Years";
include('config.inc.php');
$sql1="select * from province where PROVINCE_ID='$province' ";
$result1=mysql_query($sql1);
$fetch1=mysql_fetch_array($result1);
$province_name=$fetch1['PROVINCE_NAME'];
$sql2="select * from amphur where AMPHUR_ID='$amphur' ";
$result2=mysql_query($sql2);
$fetch2=mysql_fetch_array($result2);
$amphur_name=$fetch2['AMPHUR_NAME'];
$sql3="select * from district where DISTRICT_ID='$district' ";
$result3=mysql_query($sql3);
$fetch3=mysql_fetch_array($result3);
$district_name=$fetch3['DISTRICT_NAME'];
$sql4="update userinfo set username='$txtUsername',password='$pass_md5',name='$name',email='$email',
address='$address',province='$province_name',amphur='$amphur_name',district='$district_name',
id_province='$id_province',age='$age',txtAge='$txtAge',citizen_id='$citizen',phone='$phone',
occupation='$occupation',status='$status',online='0',date_register='$date',activate='0' where username='$user' ";
$result4= mysql_query($sql4);
?><script> document.getElement('pan2').style.display='none';</script>
<? } ?>
ดูที่ตรงบรรทัดสุดท้ายอ่ะครับ
คือจะเขียนแบบว่าให้ซ่อน form div หนึ่งครับแบบว่า document.getElement('pan2').style.display='none'; ประมาณนี้อ่ะครับ
คือจะส่งคำสั่งซ่อนนี้ไปที่หน้า 1 ถ้าทำการอัพเดทข้อมูลเรียบร้อย มันจะเขียนได้มั้ยครับ (แต่ผมลองแล้วมันไม่ได้ครับ)
หรือว่า ถ้าอัพเดทข้อมูลเรียบร้อย ให้เรียกใช้ฟั่งก์ชั่นจาวาสคริปต์ในหน้าที่ 1 แบบนี้จะทำได้มั้ยครับ หรือมีวิธีอื่น
ขอบคุณครับ
Tag : PHP, MySQL, JavaScript, Ajax
|
ประวัติการแก้ไข 2011-02-28 22:07:58 2011-02-28 22:10:12 2011-02-28 22:11:06 2011-03-01 01:43:36
|
 |
 |
 |
 |
Date :
2011-02-28 22:05:26 |
By :
เด็กโง่ |
View :
1063 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |