|
 |
|
คือว่ากด submit แล้วข้อมูลมันลงเบิ้ลซ้ำกันสอง เรคคอร์ด อะครับ(แก้ใหม่แล้วครับ ) |
|
 |
|
|
 |
 |
|
Code (PHP)
<script language="javascript">
function checkID(id)
{
if(id.length != 13) return false;
for(i=0, sum=0; i < 12; i++)
sum += parseFloat(id.charAt(i))*(13-i); if((11-sum%11)%10!=parseFloat(id.charAt(12)))
return false; return true;}
function checkForm()
{
var flag=true;
if(!checkID(document.frm001.txtpro.value))
{alert('รหัสประชาชนไม่ถูกต้อง');
frm001.txtpro.focus();
flag=false;
}
else {alert('รหัสประชาชนถูกต้อง เชิญผ่านได้');
document.frm001.submit(); <? ## ถ้าผ่านส่งค่าไปทำงานต่อที่ frm001?>
}
return flag
}
</script>
<?
$host="localhost";
$user="root";
$pw="123456";
$dbname="db_test";
$c=mysql_connect($host,$user,$pw);
if (!$c){
echo"Connect DB Error";
}
mysql_select_db($dbname);
$email=$_POST['txtemail'];
if ($email==""){$email=$_GET['txtemail'];}
$name=$_POST['txtname'];
if ($name==""){ $name=$_GET['txtname'];}
$surname=$_POST['txtsurname'];
if ($surname==""){$surname=$_GET['txtsurname'];}
$pro=$_POST['txtpro'];
if ($pro==""){$pro=$_GET['txtpro'];}
$btnubrowse=$_POST['btnubrowse'];
if ($btnubrowse==""){$btnubrowse=$_GET['btnubrowse'];}
$txtfrm001=$_POST['txtfrm001'];
$txtfrm002=$_POST['txtfrm002'];
$fileUpload=$_FILES["var"];
$_FILES["var"];
function checkemail ($checkemail) {
if (ereg("^[^@ ]+@([a-zA-Z0-9\-]+\.)+([a-zA-Z0-9\-]{2}
|net|com|gov|mil|org|edu|int|go.th|co.th)$",$checkemail) ) {
return true;
} else {
return false;
}
}
if ($email!="" && $name!="" && $surname!="" && $pro!="" && $txtfrm001!=""){
if(!checkemail($email)){
?>
<script language="javascript">
alert ('รูปแบบอีเมลไม่ถูกต้อง');
</script>
<?
$txtfrm001="";
}
$sql="INSERT INTO tb_register (pro,name,surname,email) values ('$pro','$name','$surname','$email')";
//echo $sql;
//exit;
$query= mysql_query($sql);
echo "It's Work";
} else {$txtfrm001="";}
?>
<body>
<div id="head1"></div>
<div id="body1">
<table border="1" align="center">
<tr><td>
<table width="283" border="1">
<tr><td width="87" <? if($txtfrm001=="") { echo "bgcolor='#FF0000'";}?>>กรอกข้อมูล</td><td width="96" <? if($email!="" && $name!="" && $surname!="" && $pro!="" && $txtfrm001=="txtfrm001" ){echo "bgcolor='#FF0000'";} ?>>อัพโหลดรูป</td><td width="86"<? if($fileUpload=="" && $txtfrm002=="txtfrm002" && $txtfrm001==""){echo "bgcolor='#FF0000'";} ?>>เสร็จสิ้น</td></tr>
</table>
<? if ($txtfrm001=="") { ?>
<table border="0"><form action="" method="post" enctype="multipart/form-data" name="frm001" id="frm001" onsubmit="javascript: return checkForm();">
<tr><td width="80"><label>Pro : </label></td><td width="194"><input name="txtpro" id="txtpro" type="text" maxlength="13" value="<?=$pro?>"/></td></tr>
<tr><td><label>Name : </label></td><td><input name="txtname" id="txtname" type="text" value="<?=$name?>" /></td></tr>
<tr><td><label>Surname : </label></td><td><input name="txtsurname" id="txtsurname" type="text" value="<?=$surname?>"/></td></tr>
<tr><td>Email : </td><td><input name="txtemail" id="txtemail" type="text" value="<?=$email?>" /></td></tr>
<tr><td colspan="2">
<center><input name="btnsubmit" id="btnsubmit" type="submit" value="submit"/></center></td></tr>
<input name="txtfrm001" type="hidden" id="txtfrm001" value="txtfrm001"/>
</form> <? #สิ้นสุด ฟอร์ม กรอกข้อมูล ?>
</table>
<? $query=mysql_query($sql); }
if ($email!="" && $name!="" && $surname!="" && $pro!="" && $txtfrm001=="txtfrm001"){?>
<table border="0"><tr><td width="279"><form action="Register2.php" method="post" enctype="multipart/form-data" name="frm002">
<input type="file" name="fileUpload">
<input type="submit" name="btnsubmit2" value="Submit" id="btnsubmit2">
<input name="txtfrm002" type="hidden" id="txtfrm002" value="txtfrm002"/>
</form></td></tr>
</table>
<? } ?>
</td></tr>
</table>
</div>
คือหน้า แทรก กรอกข้อมูลอะครับ พอกดsubmit มันมีข้อมูลเบิ้ลซ้ำ อะครับ ชี้แนะด้วยครับ ขอบคุณครับ

Tag : - - - -

|
|
 |
 |
 |
 |
Date :
2010-07-07 16:32:36 |
By :
alderman |
View :
1121 |
Reply :
4 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Quote:
php เขียนโปรแกรมเป็นแบบนี้ได้ด้วยหรอครับ ถ้าได้แล้วเขาเขียนยังไงกันหว่า ขอคำแนะนำหน่อยนะครับ
|
 |
 |
 |
 |
Date :
2010-07-07 17:17:16 |
By :
dekcomnvc |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เอา document.frm001.submit(); ตรงบรรทัด 018 ออกก็น่าจะหายจากอาการข้อมูลเบิ้ลนะครับ ลองดู
|
 |
 |
 |
 |
Date :
2010-07-07 21:09:44 |
By :
pnbps |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ดูเหมือนเมื่อเปิดหน้า จะ INSERT ค่าเข้าไปเลยโดยไม่ต้อง submit (ครั้งที่ 1) พอ submit ค่าก็เข้าไปในตารางอีก (ครั้งที่ 2)
เอา
<?
$sql="INSERT INTO tb_register (pro,name,surname,email) values ('$pro','$name','$surname','$email')";
$query= mysql_query($sql);
?>
ไว้อีกหน้านึงครับ
แล้วก็
form action="ใส่หน้านั้น"
|
 |
 |
 |
 |
Date :
2010-07-08 02:22:20 |
By :
yogolas |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณครับ
|
 |
 |
 |
 |
Date :
2010-07-08 11:34:22 |
By :
alderman |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|