|
 |
|
ดูโค๊ดให้หน่อยครับ พวกพี่ๆ มันขึ้น error ก็จิงครับ แต่มันแปลกๆ ครับ |
|
 |
|
|
 |
 |
|
Register.php
<?
$arrProvince ="select * from province";
$resProvince = mysql_query($arrProvince,$conn);
?>
<script type="text/javascript" SRC="js/Validate.js"></script>
<? if($_GET['action'] == "") {?>
<h3>สมัครสมาชิก(Register)</h3>
<br>
<br>
<h4> สร้าง Username และ Password</h4>
<form name="form1" id="form1" method="post" action="?name=user&file=register" onsubmit="checkForm()">
<table border="0">
<tr>
<td>Username:</td>
<td>
<input type="text" name="username" value="<? echo $_SESSION['regis']['username'];?>" maxlength="15"/>
<font color="#FF0000">* เป็นตัวอักษรหรือตัวเลข ความยาวไม่เกิน 15 ตัว</font></td>
</tr>
<tr>
<td>Password:</td>
<td>
<input type="password" name="password" maxlength="10"/>
<font color="#FF0000">* เป็นตัวอักษรหรือตัวเลข ความยาวไม่เกิน 10 ตัว</font></td>
</tr>
<tr>
<td>Re_password:</td>
<td>
<input type="password" name="repassword" maxlength="10"/>
<font color="#FF0000">* ยืนยันรหัสผ่าน</font></td>
</tr>
</table>
<br>
<h4>ข้อมูลส่วนตัว </h4>
<table width="481" height="317" border="0">
<tr>
<td width="148">ชื่อ:</td>
<td width="317">
<input type="text" name="firstname" value="<? echo $_SESSION['regis']['firstname'];?>"/>
<font color="#FF0000">*</font></td>
</tr>
<tr>
<td>นามสกุล:</td>
<td>
<input type="text" name="lastname" value="<? echo $_SESSION['regis']['lastname'];?>" />
<font color="#FF0000">*</font></td>
</tr>
<tr>
<td>เพศ:</td>
<td>
<input name="gender" type="radio" value="ผู้ชาย" id="rdo1"/> ผู้ชาย
<input name="gender" type="radio" value="ผู้หญิง" id="rdo2"/> ผู้หญิง
<font color="#FF0000">*</font></td>
</tr>
<tr>
<td>Email:</td>
<td>
<input type="text" name="email" value="<? echo $_SESSION['regis']['email'];?>"/>
<font color="#FF0000">*</font></td>
</tr>
<tr>
<td>ที่อยู่:</td>
<td>
<textarea name="address" rows="10" cols="40"><? echo $_SESSION['regis']['address'];?></textarea><font color="#FF0000">*</font>
</td>
</tr>
<tr>
<td height="74">จังหวัด:</td>
<td>
<select name="province_id">
<option value="--"> </option>
<? while($resData = mysql_fetch_array($resProvince)){ ?>
<option value="<?=$resData['province_id']?>"><? echo($resData['province_name']);?></option>
<? }?>
</select>
<font color="#FF0000">*</font></td>
</tr>
<tr>
<td>รหัสไปรษณีย์:</td>
<td>
<input type="text" name="zipcode" maxlength="6" size="6"value="<? echo $_SESSION['regis']['zipcode'];?>" onKeyUp="IsNumeric(this.value,this)"/>
<font color="#FF0000">* เป็นตัวเลขเท่านั้น</font></td>
</tr>
<tr>
<td>เบอร์โทรศัพท์:</td>
<td>
<input type="text" name="tel" maxlength="9" size="9"value="<? echo $_SESSION['regis']['tel'];?>" onKeyUp="IsNumeric(this.value,this)"/>
<font color="#FF0000">เป็นตัวเลขเท่านั้น</font></td>
</tr>
<tr>
<td>เบอร์มือถือ:</td>
<td>
<input type="text" name="mobile" maxlength="10" size="10" value="<? echo $_SESSION['regis']['mobile'];?>" onKeyUp="IsNumeric(this.value,this)"/>
<font color="#FF0000">* เป็นตัวเลขเท่านั้น</font></td>
</tr>
<tr>
<td colspan="3"><div align="center" class="style1"><b>หมายเหตุ ฟอร์มที่มีเครื่องหมาย (<font color="#FF0000">*</font>) ด้องใส่ข้อมูลทุกฟอร์ม </b></div></td>
</tr>
</table>
<p>
<br>
<input type="submit" name="Submit" value="ตกลง" />
<input type="reset" name="Submit2" value="ยกเลิก" />
</p>
</form>
<p>
<? } elseif($_GET['action'] == "register") {
$_SESSION['regis'] = $_POST;
//echo "<pre>"; print_r($_POST);
$firstname = ($_POST['firstname']);
$lastname = ($_POST['lastname']);
$gender = ($_POST['gender']);
$email = ($_POST['email']);
$address = ($_POST['address']);
$province = ($_POST['province']);
$zipcode = ($_POST['zipcode']);
$tel = ($_POST['tel']);
$mobile = ($_POST['mobile']);
if($msg){
$_SESSION['msg']= $msg;
echo "<script type='text/javascript'>";
echo "location.href='?name=user&file=register' ";
echo "</script>";
}else{
$password = md5($_POST['password']);
//เช็คค่าที่กรอกใน Username ถ้าซ้ำขึ้น Error
$str="select * from member where username ='".$_POST['username']."' ";
$result = mysql_query($str,$conn);
$res = mysql_num_rows($result);
if ($res){
$msg="ชื่อ Username ซ้ำ กรุณาเปลี่ยนใหม่";
$_SESSION['msg']= $msg;
echo "<script type='text/javascript'>";
echo "location.href='?name=user&file=register' ";
echo "</script>";
}else{
// ทำการ insert ข้อมูล ลงในตาราง Member
$strSQL="insert into member (mem_firstname,mem_lastname,gender,mem_email,mem_address,province_id,zipcode,mem_tel,mem_mobile,username,password)";
$strSQL .="values('".$_POST['firstname']."','".$_POST['lastname']."','".$_POST['gender']."','".$_POST['email']."' ,'".$_POST['address']."' ,'".$_POST['province_id']."','".$_POST['zipcode']."','".$_POST['tel']."','".$_POST['mobile']."' ,'".$_POST['username']."' ,'".$password."')";
//echo "$strSQL";
mysql_query($strSQL,$conn);
mysql_close($conn);
}
}
?>
<center>
<h4>ข้อมูลถูกบันทึกแล้ว</h4><br>
<a href="index.php?name=user&file=login">Login </a> </center>
<? } ?>
Validate.js
function checkForm() {
if (form1.username.value.replace(/\s+$/, "") =="") {
alert("กรุณากรอก Username");
form1.username.focus();
return false;
}
if (form1.password.value.replace(/\s+$/, "") =="") {
alert("กรุณากรอก Password");
form1.password.focus();
return false;
}
if (form1.repassword.value!==form1.password.value) {
alert("กรุณากรอก Password ให้ตรงกัน");
return false;
}
if (form1.firstname.value.replace(/\s+$/, "") =="") {
alert("กรุณากรอกชื่อ");
form1.firstname.focus();
return false;
}
if (form1.lastname.value.replace(/\s+$/, "") =="") {
alert("กรุณากรอกนามสกุล");
form1.lastname.focus();
return false;
}
if(form1.rdo1.checked == false && document.form1.rdo2.checked == false ){
alert('กรุณาเลือกเพศ ');
return false;
}
if (form1.email.value.replace(/\s+$/, "") =="") {
alert("กรุณากรอก E-Mail");
form1.email.focus();
return false;
}
if (form1.address.value.replace(/\s+$/, "") =="") {
alert("กรุณากรอกที่อยู่");
form1.address.focus();
return false;
}
if (form1.zipcode.value.replace(/\s+$/, "") =="") {
alert("กรุณากรอกรหัสไปรษณีย์");
form1.zipcode.focus();
return false;
}
if (form1.mobile.value.replace(/\s+$/, "") =="") {
alert("กรุณากรอกเบอร์มือถือ");
form1.mobile.focus();
return false;
}
}
มันขึ้น error ก็จิงครับ แต่มันแปลกๆครับ
Tag : - - - -

|
|
 |
 |
 |
 |
Date :
2009-12-05 22:50:07 |
By :
อยากเก่ง |
View :
892 |
Reply :
7 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มันขึ้น alert ก็จริงครับ แต่มันไม่ยอมfocus ทั้งๆที่โค๊ดก็เขียนแล้ว
พอกด ปุ่มตกลง มันก็เด้ง หน้าเดิมตลอดครับ
|
 |
 |
 |
 |
Date :
2009-12-05 23:12:05 |
By :
อยากเก่ง |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองเปลี่ยน จาก focus() เป็น select() ดูนะครับ ดูจะเหมาะกับ textbox มากกว่า
ลองดูครับ
|
 |
 |
 |
 |
Date :
2009-12-05 23:47:56 |
By :
kenessar |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
กดตกลงทีไร มันเด้งมาหน้าเดิมตลอดเลยอะครับ
เป็นเพราะอะไรเหรอครับ
|
 |
 |
 |
 |
Date :
2009-12-06 00:09:40 |
By :
อยากเก่ง |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไม่งั้นก็เปลี่ยน $_GET['action'] ให้เป็น $_GET['file'] แทนครับ เพราะดูแล้วจะใช้ ?file=register ทั้งไฟล์เลย
|
 |
 |
 |
 |
Date :
2009-12-06 00:32:18 |
By :
kenessar |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมลองเปลี่ยนแล้วครับพี่ครับ
คือมันขึ้นalert มาน่ะครับ ตามเงื่อนไขที่ดักจาวาสคริปไป
แต่ที่ผมสงสัยคือ พอมันขึ้น alert มาแล้วอะครับ
ความจริงcursor มันจะต้อง focus ดิครับ ว่า
alert ขึ้นตรงไหน ก็ focus ตรงนั้น แต่นี้คือ เด้งหน้าเดิมตลอดเลย
เป็นเพราะอะไรเหรอครับ ???
|
 |
 |
 |
 |
Date :
2009-12-06 19:41:58 |
By :
อยากเก่ง |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|