|
 |
|
insert ข้อมูล ไม่ได้อ่ะ รบกวนผู้รู้ทุกท่านเลยนะครับ ผมมม |
|
 |
|
|
 |
 |
|
<?php
$username=$_SESSION['u_name'];
if(!isset($_SESSION['u_name'])){
echo "<script>window.location='index.php';</script>";
exit();
}
include("config.inc.php");
$stu_id = $_POST['stu_id'];
$stu_pic = $_POST['stu_pic'];
$title = $_POST['title'];
$name = $_POST['name'];
$nicname = $_POST['nicname'];
$origin = $_POST['origin'];
$nation = $_POST['nation'];
$religion = $_POST['religion'];
$date = $_POST['date'];
$month = $_POST['month'];
$year = $_POST['year'];
$siblings = $_POST['siblings'];
$num = $_POST['num'];
$num_work = $_POST['num_work'];
$study = $_POST['study'];
$Expen = $_POST['Expen'];
$tel = $_POST['tel'];
$spc = $_POST['spc'];
$sql="select * from student where stu_id ='$stu_id' ";
$result=mysql_query($sql);
$num_row=mysql_num_rows($result);
if($num_row==" ") {
$sql = "insert into student values ('$stu_id','$stu_pic','$title','$name','$nicname','$origin','$nation','$religion','$date','$month','$year','$siblings','$num','$num_work','$study','$Expen','$tel','$spc')";
mysql_query($sql) or die ("error=$sql");
//ข้อมูลเพื่อนสนิท
$f_name = $_POST['f_name'];
$f_program = $_POST['f_program'];
$f_tel = $_POST['f_tel'];
$add = $_POST['add'];
$sql2="insert into stu_friend values ('$stu_id','$f_name','$f_program','$f_tel','$add')";
mysql_query($sql2) or die ("error=$sql2");
//ข้อมูลบิดา - มารดานักศึกษา
$far_name = $_POST['far_name'];
$far_occup = $_POST['far_occup'];
$far_day = $_POST['far_day'];
$far_month = $_POST['far_month'];
$far_year = $_POST['far_year'];
$far_revenue = $_POST['far_revenue'];
$far_add = $_POST['far_add'];
$far_mobile = $_POST['far_mobile'];
$mar_name = $_POST['mar_name'];
$mar_occup = $_POST['mar_occup'];
$mar_day = $_POST['mar_day'];
$mar_month = $_POST['mar_month'];
$mar_year = $_POST['mar_year'];
$mar_revenue = $_POST['mar_revenue'];
$mar_add = $_POST['mar_add'];
$mar_mobile = $_POST['mar_mobile'];
$sql3="insert into parents values ('$stu_id','$far_name','$far_occup','$far_day','$far_month','$far_year','$far_revenue','$far_add','$far_mobile','$mar_name','$mar_occup','$mar_day','$mar_month','$mar_year','$mar_revenue','$mar_add','$mar_mobile')";
mysql_query($sql3) or die ("error=sql3");
//ข้อมูลผู้ปกครองที่ติดต่อได้ในกรณีฉุกเฉิน
$c_relation = $_POST['c_relation'];
$c_name = $_POST['c_name'];
$c_day = $_POST['c_day'];
$c_month = $_POST['c_month'];
$c_year = $_POST['c_year'];
$c_add = $_POST['c_add'];
$c_hometel = $_POST['c_hometel'];
$c_mobile = $_POST['c_mobile'];
$sql4="insert into contact values ('$stu_id','$c_relation','$c_name','$c_day','$c_month','$c_year','$c_add','$c_hometel','$c_mobile')";
mysql_query($sql4) or die ("error=$sql4");
$sql5="insert into account values ('','$stu_id','$stu_id','$stu_id','2')" ;
mysql_query($sql5) or die ("error=$sql5");
echo "<center>ลงทะเบียนเรียบร้อยแล้ว</center>";
echo "<meta http-equiv = refresh ; content = '3 ; url=../nurse_npru/index.php'>";
}else{
echo "<script>alert ('รหัสนักศึกษานี้ $stu_id นี้ลงทะเบียนแล้วกรุณากรอกใหม่');history.back();</script>";
exit();
}
?>
ครั้งแรกก็ได้นะครับ
แต่พอเปลี่ยนฐานข้อมูล ก็ไม่ได้อีกเลย
พอกลับมาใช้ฐานข้อมูลเดิม เวอร์ชั่นเดิม ก็ไม่ได้อีกอ่ะ
Tag : PHP

|
|
 |
 |
 |
 |
Date :
2010-09-23 14:21:11 |
By :
ปุ้ย |
View :
832 |
Reply :
4 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<?php
$username=$_SESSION['u_name'];
if(!isset($_SESSION['u_name'])){
echo "<script>window.location='index.php';</script>";
exit();
}
include("config.inc.php");
$stu_id = $_POST['stu_id'];
$stu_pic = $_POST['stu_pic'];
$title = $_POST['title'];
$name = $_POST['name'];
$nicname = $_POST['nicname'];
$origin = $_POST['origin'];
$nation = $_POST['nation'];
$religion = $_POST['religion'];
$date = $_POST['date'];
$month = $_POST['month'];
$year = $_POST['year'];
$siblings = $_POST['siblings'];
$num = $_POST['num'];
$num_work = $_POST['num_work'];
$study = $_POST['study'];
$Expen = $_POST['Expen'];
$tel = $_POST['tel'];
$spc = $_POST['spc'];
$sql="select * from student where stu_id ='$stu_id' "; +++++++++++++ตัวแปลซ้ำรึเปล่าคะ
$result=mysql_query($sql);
$num_row=mysql_num_rows($result);
if($num_row==" ") {
$sql = "insert into student values +++++++++++++ตัวแปลซ้ำรึเปล่าคะ
('$stu_id','$stu_pic','$title','$name','$nicname','$origin','$nation','$religion','$date','$month','$year','$siblings','$num','$num_work','$study','$Expen','$tel','$spc')";
mysql_query($sql) or die ("error=$sql");
//ข้อมูลเพื่อนสนิท
$f_name = $_POST['f_name'];
$f_program = $_POST['f_program'];
$f_tel = $_POST['f_tel'];
$add = $_POST['add'];
$sql2="insert into stu_friend values ('$stu_id','$f_name','$f_program','$f_tel','$add')";
mysql_query($sql2) or die ("error=$sql2");
//ข้อมูลบิดา - มารดานักศึกษา
$far_name = $_POST['far_name'];
$far_occup = $_POST['far_occup'];
$far_day = $_POST['far_day'];
$far_month = $_POST['far_month'];
$far_year = $_POST['far_year'];
$far_revenue = $_POST['far_revenue'];
$far_add = $_POST['far_add'];
$far_mobile = $_POST['far_mobile'];
$mar_name = $_POST['mar_name'];
$mar_occup = $_POST['mar_occup'];
$mar_day = $_POST['mar_day'];
$mar_month = $_POST['mar_month'];
$mar_year = $_POST['mar_year'];
$mar_revenue = $_POST['mar_revenue'];
$mar_add = $_POST['mar_add'];
$mar_mobile = $_POST['mar_mobile'];
$sql3="insert into parents values ('$stu_id','$far_name','$far_occup','$far_day','$far_month','$far_year','$far_revenue','$far_add','$far_mobile','$mar_name','$mar_occup','$mar_day','$mar_month','$mar_year','$mar_revenue','$mar_add','$mar_mobile')";
mysql_query($sql3) or die ("error=sql3");
//ข้อมูลผู้ปกครองที่ติดต่อได้ในกรณีฉุกเฉิน
$c_relation = $_POST['c_relation'];
$c_name = $_POST['c_name'];
$c_day = $_POST['c_day'];
$c_month = $_POST['c_month'];
$c_year = $_POST['c_year'];
$c_add = $_POST['c_add'];
$c_hometel = $_POST['c_hometel'];
$c_mobile = $_POST['c_mobile'];
$sql4="insert into contact values ('$stu_id','$c_relation','$c_name','$c_day','$c_month','$c_year','$c_add','$c_hometel','$c_mobile')";
mysql_query($sql4) or die ("error=$sql4");
$sql5="insert into account values ('','$stu_id','$stu_id','$stu_id','2')" ;
mysql_query($sql5) or die ("error=$sql5");
echo "<center>ลงทะเบียนเรียบร้อยแล้ว</center>";
echo "<meta http-equiv = refresh ; content = '3 ; url=../nurse_npru/index.php'>";
}else{
echo "<script>alert ('รหัสนักศึกษานี้ $stu_id นี้ลงทะเบียนแล้วกรุณากรอกใหม่');history.back();</script>";
exit();
}
?>
|
ประวัติการแก้ไข 2010-09-23 14:28:38
 |
 |
 |
 |
Date :
2010-09-23 14:27:58 |
By :
naked13 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
$num_row=mysql_num_rows($result);
if($num_row <= 0) {
|
 |
 |
 |
 |
Date :
2010-09-23 14:57:49 |
By :
PlaKriM |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
1. นับ Field ใน Table ว่าครบตามจำนวนหรือยังครับ
2. if($num_row==" ") บรรทัดที่ 32 ครับ หาก Select ไม่เจอก็จะมีค่าเป็น 0 ไม่ใช่ " " เพราะฉนั้นจะไม่เข้าเงื่อนไขครับ
ตัวอย่างที่น้องเขียนในบรรทัดที่ 32
------------Select เจอ คือ $num_row = 1
------------Select ไม่เจอ $num_row =0
*********** แต่เราได้กำหนด ว่า ถ้า $num_row==" " ก็ให้ทำตามเงื่อนไขต่อไป มันก็จะหลุดเสียทั้งหมดแน่นอนครับ
3. บรรทัดที่ 64 mysql_query($sql3) or die ("error=sql3"); ใส่ $sql3 ด้วยนะครับ
|
 |
 |
 |
 |
Date :
2010-09-24 11:36:44 |
By :
compeng |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 02
|