|
 |
|
ข้อมูลมันไม่แอดลงฐานข้อมูลอะครับ กด submit แล้วไม่มีอะไรเกิดขึ้น |
|
 |
|
|
 |
 |
|
Code (PHP)
<?php
session_start() ;
/* add by kergrit(redthird.com) for compatible global variable off/on php.ini */
$id_card_txt = $_POST['id_card_txt'];
$user_name = $_POST['user_name'];
$pwd_name1 = $_POST['pwd_name1'];
$email = $_POST['email'];
$name = $_POST['name'];
$sex = $_POST['sex'];
$dateofbirth = $_POST['dateInput'];
$address = $_POST['address'];
$province = $_POST['province_id'];
$amper = $_POST['amphur_id'];
$zipcode = $_POST['zipcode'];
$phone = $_POST['phone'];
$education = $_POST['education'];
$work = $_POST['work'];
$emptype_id = $_POST['emptype_id'];
$Submit = $_POST['Submit'];
$ok = $_POST['ok'];
/* end of add */
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=tis-620">
<title>:: ผลการสมัครสมาชิก ::</title>
</head>
<body>
<?php
include("config.inc.php") ;
// ตรวจสอบ กรณีที่เรียกหน้านี้ขึ้นมาเลยโดยที่กรอกข้อมูลไม่ครบ
if($id_card_txt=="" || $user_name=="" || $pwd_name1=="" || $email=="" || $name=="" ) {
echo "<meta http-equiv='refresh' content='0; url='signup.php'>" ;
}
ถ้ากรอกอีเมล์ไม่ถูกต้อง
if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)$",$email)){
echo "<br><br><center><font size='3' face='MS Sans Serif'><b>กรุณากรอกอีเมล์ให้ถูกต้องด้วยครับ</b></font>" ;
echo "<br><br><input type='button' value='edit your email' onclick='history.back();'></center></body></html>" ;
exit() ;
}
if((isset($ok)) and ($ok!="ok_pass")) {
echo "<meta http-equiv='refresh' content='0; url=signup.php'>" ;
}
// ตรวจสอบว่ามีชื่อ user นี้ใช้ไปหรือยัง
$sql = "select Username from member where Username='$user_name'" ;
$result = mysql_query($sql) ;
$numrow = mysql_num_rows($result) ;
if($numrow!=0) {
echo "<br><br><center><font size='3' face='MS Sans Serif'>ขอโทษด้วยครับ user $user_name นี้ ได้มีผู้ใช้ไปแล้วครับ กรุณาเปลี่ยนชื่อ Login ใหม่" ;
echo "<br><br><input type='button' value='back to edit' onclick='history.back();'></center></body></html>" ;
exit() ;
}
// ถ้ายังไม่มีผู้ใช้ชื่อ user นี้
$sql = "select * from member" ;
$result = mysql_query($sql) ;
$member_id = $yourcode.$member_in; // รหัสสมาชิกเช่น ip0001
$result = mysql_query("insert into member (Member_ID,Personal_ID,Username,Password,E-Mail,Name,Sex,DateOfBirth,Emp_Address,Province,Amphur,Zipcode,Emp_Tel,Education,Work,EmpType_ID)
values('$member_id','$id_card_txt','$user_name','$pwd_name1','$email','$name','sex','dateInput','$address','$province','$amper','$zipcode','$phone','education','work','emptype_id')");
if($result) {
$_SESSION['login_true'] = $user_name;
echo "<center><font size=\"3\" face='MS Sans Serif'><b>ขอบคุณมากครับ สำหรับการลงทะเบียนเป็นสมาชิก</b></font></center>";
echo "<meta http-equiv='refresh' content='2; url=member_detail.php'>" ;
}
?>
</body>
</html>
โค้ดตามนี้ครับ ช่วยดูให้หน่อยครับ ว่ามีตรงไหนตกหล่นไปหรือเปล่า หรืออยากได้โค้ดตัวไหนดูเพิ่มบอกได้ครับ
Tag : PHP

|
|
 |
 |
 |
 |
Date :
2012-07-12 16:21:48 |
By :
zmug |
View :
1401 |
Reply :
16 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
'sex','dateInput', 'education','work','emptype_id'
ข้อมูลพวกนี้ไม่ใช่ตัวแปรครับ
อาจจะเกิดจากประเภทข้อมูลของฟิลด์บางตัวถูกกำหนดเป็น INT ซึ่งข้างบนเป็นข้อมูล string ครับ มันเลยไม่เข้า
|
 |
 |
 |
 |
Date :
2012-07-12 16:30:44 |
By :
Pine |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แก้แล้ว ก็เหมือนเดิมอะครับ ละก็ประเภทของข้อมูลในดาต้าเบส ก็เป็น string ครับ
|
 |
 |
 |
 |
Date :
2012-07-12 16:44:12 |
By :
zmug |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
'sex','dateInput'
'$sex','$dateInput'
อูย..มีคนตอบไปละ โทษที
|
ประวัติการแก้ไข 2012-07-12 16:50:01
 |
 |
 |
 |
Date :
2012-07-12 16:49:07 |
By :
นู๋น้อย |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองเปลี่ยนเป็น
Code (PHP)
$sql = ("insert into member (Member_ID,Personal_ID,Username,Password,E-Mail,Name,Sex,DateOfBirth,Emp_Address,Province,Amphur,Zipcode,Emp_Tel,Education,Work,EmpType_ID)
values('$member_id','$id_card_txt','$user_name','$pwd_name1','$email','$name','sex','dateInput','$address','$province','$amper','$zipcode','$phone','education','work','emptype_id')");
echo $sql;
//$result = mysql_query($sql);
แล้วเอาค่าที่ echo ไปแปะใน phpMyAdmin ครับ ดูว่ามันแจ้งอะไรไหม ถ้าไม่แจ้งข้อมูลเข้าไหม นะครับ
|
 |
 |
 |
 |
Date :
2012-07-12 16:49:16 |
By :
Pine |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|

นี้เป็นฟิลในตารางครับ ลองเปลี่ยนตามที่ Pine แนะนำแล้ว แต่ยังเออเร่อครับ
หรือว่าต้องเรียงตัวแปรการแอดข้อมูลตาม ฟิลในตารางครับ
ขอบคุณทุกคำตอบครับผม
|
 |
 |
 |
 |
Date :
2012-07-12 17:15:47 |
By :
zmug |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|

echo แล้ว ขึ้นแบบนี้อะครับ ภาษาต่างด้าว มันเกี่ยวกับแอดข้อมูลไม่ลงหรือเปล่าครับ
|
 |
 |
 |
 |
Date :
2012-07-12 17:20:49 |
By :
zmug |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมว่าลอง echo คำสั่ง sql มาดูนะคับ เท่าที่เดาน่าจะเป็น
- รูปแบบวันเดือนปี
- รูปแบบของข้อมูลไม่ถูกตาม datatype ของ database
- pk ซ้ำ
|
 |
 |
 |
 |
Date :
2012-07-12 17:22:19 |
By :
ichiko |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมว่าน่าจะตั้ง ภาษาเป็นแบบ utf-8 นะคับ
แล้วตัวแปรบางตัวก็ไม่ได้ใส่ $ ไปข้างหน้าตัวแปร
|
 |
 |
 |
 |
Date :
2012-07-12 17:26:25 |
By :
ichiko |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<?php
$link = mysql_connect("localhost", "root", "") or die (mysql_error());
$sel_db = mysql_select_db("yourdatabases", $link);
/* sql insert */
$sql = "INSERT INTO yourtable (val1, val2, val3)VALUES ('".$val1."', '".$val2."', '".$val3."');";
$qr = mysql_query($sql);
if($qr){
echo "success !!!";
}else{
echo "Error !!!";
}
?>
ผมแนะนำแบบนี้ดีกว่านะครับจะได้เข้าใจ Code ด้วย
|
 |
 |
 |
 |
Date :
2012-07-12 17:28:25 |
By :
popnakub |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณทุกคำตอบมากครับ เดี๋ยวจะลองแก้ไขดูครับ
|
 |
 |
 |
 |
Date :
2012-07-12 17:35:49 |
By :
zmug |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<?php
session_start() ;
$id_card_txt = $_POST['id_card_txt'];
$phone = $_POST['phone'];
$user_name = $_POST['user_name'];
$pwd_name1 = $_POST['pwd_name1'];
$email = $_POST['e-mail'];
$name = $_POST['name'];
$sex = $_POST['sex'];
$address = $_POST['address'];
$amper = $_POST['amphur_id'];
$province = $_POST['province_id'];
$zipcode = $_POST['zipcode'];
$education = $_POST['education'];
$work = $_POST['work'];
$dateofbirth = $_POST['dateInput'];
$emptype_id = $_POST['emptype_id'];
$Submit = $_POST['Submit'];
$ok = $_POST['ok'];
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>:: ผลการสมัครสมาชิก ::</title>
</head>
<body>
<?php
$link = mysql_connect("localhost", "root", "231619") or die (mysql_error());
$sel_db = mysql_select_db("membersystem",$link);
// ตรวจสอบ กรณีที่เรียกหน้านี้ขึ้นมาเลยโดยที่กรอกข้อมูลไม่ครบ
if($id_card_txt=="" || $user_name=="" || $pwd_name1=="" || $email=="" || $name=="" ) {
echo "<meta http-equiv='refresh' content='0; url='signup.php'>" ;
}
// ถ้ากรอกอีเมล์ไม่ถูกต้อง
if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)$",$email)){
echo "<br><br><center><font size='3' face='MS Sans Serif'><b>กรุณากรอกอีเมล์ให้ถูกต้องด้วยครับ</b></font>" ;
echo "<br><br><input type='button' value='edit your email' onclick='history.back();'></center></body></html>" ;
exit() ;
}
if((isset($ok)) and ($ok!="ok_pass")) {
echo "<meta http-equiv='refresh' content='0; url=signup.php'>" ;
}
// ตรวจสอบว่ามีชื่อ user นี้ใช้ไปหรือยัง
$sql = "select Username from member where Username='$user_name'" ;
$result = mysql_query($sql) ;
$numrow = mysql_num_rows($result) ;
if($numrow!=0) {
echo "<br><br><center><font size='3' face='MS Sans Serif'>ขอโทษด้วยครับ user $user_name นี้ ได้มีผู้ใช้ไปแล้วครับ กรุณาเปลี่ยนชื่อ Login ใหม่" ;
echo "<br><br><input type='button' value='back to edit' onclick='history.back();'></center></body></html>" ;
exit() ;
}
$member_id = $yourcode.$member_in; // รหัสสมาชิกเช่น ip0001
/* sql insert */
$sql = "INSERT INTO member(Member_ID,Personal_ID,Username,Password,E-Mail,Name,Sex,DateOfBirth,Emp_Address,Province,Amphur,Zipcode,Emp_Tel,Education,Work,EmpType_ID)values('".$member_id."','".$id_card_txt."','".$user_name."','".$pwd_name1."','".$email."','".$name."','".$sex."','".$dateInput."','".$address."','".$province."','".$amper."','".$zipcode."','".$phone."','".$education."','".$work."','".$emptype_id."');";
$qr = mysql_query($sql);
if($qr){
echo "success !!!";
}else{
echo "Error !!!";
}
?>
</body>
</html>
ลองเปลี่ยน code ตามที่พี่ popjung แนะนำ แต่พอ submit ลงฐานข้อมูลแล้ว มันขึ้น Error อะครับ ช่วยดูให้ทีครับ
|
 |
 |
 |
 |
Date :
2012-07-12 18:19:41 |
By :
zmug |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ภาษาต่างดาวไม่เกี่ยวครับ ปัญหาคือมันไม่เข้าฐานข้อมูล
ตรงคห.6 พอ echo ออกมาแล้ว ก๊อปไว้ เอาไปแปะใน SQL ของ phpMyAdmin ครับ
มันจะแจ้ง error ว่าทำไมมันไม่เข้า ถ้าไม่เข้า แสดงว่า syntax ผิด หรือ ชนิดของข้อมูลกับฟิลด์ไม่ตรงกันครับ
หรือถ้ามันเข้า แสดงว่าโค้ดตรงการเชื่อมต่อมีปัญหาครับ
|
 |
 |
 |
 |
Date :
2012-07-12 19:09:32 |
By :
Pine |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณครับ ตอนนี้แอดได้แล้ว
มีปัญหาใหม่ คือ ข้อมูลที่แอดลงไปโชว์เป็นภาษา ทัà¸à¸ªà¸´à¸™ ชินวัด ในฐานข้อมูลใช้ utf8 โค้ด php ที่เขียนก็ใช้ utf8 ไม่ทราบว่าเป็นเพราะอะไรหรอครับ
|
 |
 |
 |
 |
Date :
2012-07-12 20:42:45 |
By :
zmug |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คือ แอดข้อมูลผ่านฟอร์ม php นะครับ ที่เป็นภาษาต่างด้าว แต่ถ้าแอดข้อมูลผ่านฐานข้อมูลเลยเป็นภาษาไทยครับ
|
 |
 |
 |
 |
Date :
2012-07-12 20:45:07 |
By :
zmug |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ได้แล้วคับ ขอบคุณมากครับ
|
 |
 |
 |
 |
Date :
2012-07-12 21:07:54 |
By :
zmug |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
นำาโค้ชที่ถูกมาให้ชมหน่อยได้เปล่าครับ
พอดีอยาเห็ฯโค้ชที่ถูกต้องอะครับ
แล้วก็ช่วยบอกตรง ตอนนี้แอดได้แล้ว
มีปัญหาใหม่ คือ ข้อมูลที่แอดลงไปโชว์เป็นภาษา ทัà¸à¸ªà¸´à¸™ ชินวัด ในฐานข้อมูลใช้ utf8 โค้ด php ที่เขียนก็ใช้ utf8 ไม่ทราบว่าเป็นเพราะอะไรหรอครับ
เป็นเหมือนกันครับ
ช่วยหน่อยครับ
ฃอบคุณร่วงหน้าครับ
|
 |
 |
 |
 |
Date :
2012-10-25 18:21:28 |
By :
nickky |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 05
|