|
 |
|
ใคร เคย เขียน php กับ mysql ด้วยการ insert ข้อมล พร้อมกัน หลาย table บ้าง |
|
 |
|
|
 |
 |
|
Code (PHP)
//tatle1
//$sql="insert into graduated_profile (Prefix,Prefix_Other,Name,LName,DateOfBirth,IDCard_Num,Semester_Type, Course_Type,GPA,Program,Student_ID,Home_Number,Mu,Village_Name, Lane,Road,Distric,City,Province,Postcode,Home_Tel,Mobile,Fax,Email) values('".$_POST[Prefix]."','".$_POST[Prefix_Other]."','".$_POST[Name]."', '".$_POST[LName]."','".$_POST[Day].'/'.$_POST[Month].'/'.$_POST[Year]."', '".$_POST[IDCard_Num]."','".$_POST[Semester_Type]."','".$_POST[Course_Type]."', '".$_POST[GPA]."','".$_POST[Program]."','".$_POST[Student_ID]."','".$_POST[Home_Number]."' ,'".$_POST[Mu]."','".$_POST[Village_Name]."','".$_POST[Lane]."','".$_POST[Road]."' ,'".$_POST[Distric]."','".$_POST[City]."','".$_POST[Province]."','".$_POST[Postcode]."' ,'".$_POST[Home_Tel]."','".$_POST[Mobile]."','".$_POST[Fax]."','".$_POST[Email]."')";
//tatle3
//$sql="insert into awards (Student_ID,Get_Awrd,Award_Name1,Name1,Award_Type1,Award_Type_Other1, Get_Date1,Get_Date_When1,Get_from1,Award_Name2,Name2,Award_Type2, Award_Type_Other2,Get_Date2,Get_Date_When2,Get_form2)values ('".$_POST[Student_ID]."','".$_POST[Get_Awrd]."','".$_POST[Award_Name1]."' ,'".$_POST[Name1]."','".$_POST[Award_Type1]."' ,'".$_POST[Award_Type_Other1]."','".$_POST[Day1].'/'.$_POST[Month1].'/'.$_POST[Year2]."', '".$_POST[Get_Date_When1]."','".$_POST[Get_from1]."','".$_POST[Award_Name2]."', '".$_POST[Name2]."','".$_POST[Award_Type2]."','".$_POST[Award_Type_Other2]."', '".$_POST[Day2].'/'.$_POST[Month2].'/'.$_POST[Year2]."','".$_POST[Get_Date_When2]."','".$_POST[Get_from2]."')";
//tatle4
//$sql="insert into work_status (Student_ID,Work_Status,After_Graduated)values('".$_POST[Student_ID]."' ,'".$_POST[Work_Status]."','".$_POST[After_Graduated]."')";
//tatle5
//$sql="insert into work (Student_ID,Work_Type,Work_Type_Other,Position,Salary,Time_To_Work, Special_Option,Special_Option_Other,Direct_Field,Want_to_Study) values('".$_POST[Student_ID]."','".$_POST[Work_Type]."', '".$_POST[Work_Type_Other]."','".$_POST[Position]."','".$_POST[Salary]."' ,'".$_POST[Time_To_Work]."','".$_POST[Special_Option]."' ,'".$_POST[Special_Option_Other]."','".$_POST[Direct_Field]."','".$_POST[Want_to_Study]."')";
//tatle6
//$sql="insert into suggestion (Student_ID,Curriculum,Curriculum_Other,Suggestion_Program, Suggestion_Study,Suggestion_Activity)values('".$_POST[Student_ID]."', '".$_POST[Curriculum]."','".$_POST[Curriculum_Other]."', '".$_POST[Suggestion_Program]."','".$_POST[Suggestion_Study]."','".$_POST[Suggestion_Activity]."')";
$query=mysql_query($sql);
if($query){
?>
<script>
alert("เพิ่มข้อมูล เรียบร้อยแล้ว");
</script>
<?
echo "<meta http-equiv='refresh' content='0;url=questionnaire.php'>";
}else{
?>
<script>
alert("ไม่สามารถเพิ่มข้อมูลได้");
</script>
<?
echo "<meta http-equiv='refresh' content='0;url=questionnaire.php'>";
}
}
?>
Tag : PHP, MySQL

|
|
 |
 |
 |
 |
Date :
2011-03-18 02:24:41 |
By :
ckcr |
View :
1093 |
Reply :
5 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เขียนหลาย query ครับ
Code (PHP)
$sql="";
mysql_query($sql);
$sql1="";
mysql_query($sql1);
$sql2="";
mysql_query($sql2);
$sql3="";
mysql_query($sql3);
|
 |
 |
 |
 |
Date :
2011-03-18 06:20:05 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
$sql="";
$query=mysql_query($sql);
$sql1="";
$query=mysql_query($sql1);
$sql2="";
$query=mysql_query($sql2);
$sql3="";
$query=mysql_query($sql3)
if($query){
?>
<script>
alert("เพิ่มข้อมูล เรียบร้อยแล้ว");
</script>
<?
echo "<meta http-equiv='refresh' content='0;url=questionnaire.php'>";
}else{
?>
<script>
alert("ไม่สามารถเพิ่มข้อมูลได้");
</script>
<?
echo "<meta http-equiv='refresh' content='0;url=questionnaire.php'>";
}
}
ใช่แบบนี้เปล่าครับ
|
ประวัติการแก้ไข 2011-03-18 10:58:47
 |
 |
 |
 |
Date :
2011-03-18 10:56:57 |
By :
ckcr |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ครับ แต่ถ้าต้องการความถูกต้องของการ insert ทั้งหมดแล้วค่อย commit ลองใช้ Transaction Commint/Rollback มาครอบครับ
|
 |
 |
 |
 |
Date :
2011-03-18 11:01:41 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
การงใช้ Transaction Commint/Rollback ใช้ได้ กับทุก กรณีเลยใช่ไมครับ
ไม่เคยลอง ความรู้ใหม่น่าสนใจ
ขอบคุณมาก ครับ
|
 |
 |
 |
 |
Date :
2011-03-18 11:12:13 |
By :
ckcr |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ในบทความมีคำอธิบายครับ 
|
 |
 |
 |
 |
Date :
2011-03-18 12:35:54 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 05
|