|
 |
|
ไม่ Update ไม่ Insert ลงฐานข้อมูลสักทีครับ ช่วยดูให้หน่อยนะครับ |
|
 |
|
|
 |
 |
|
วานผู้รู้ ช่วยหน่อยนะครับ คือ ผมติดปัญหา เขียนคำสั่งให้ Update และ Insert ข้อมูลลง 2ตาราง ครับ แต่ไม่ยอมลงสักที


อันนี้โค๊ดphp ครับ
Code (PHP)
<?php
include"connect.php" //เรียกใช้การเชื่อมต่อข้อมูลจากไฟล์ connect.php
?>
<?php
mysql_select_db("$db_name") or die("no database");
mysql_query("SET NAMES utf8");
$name2 ="";
$id_person2="";
$position2="";
$section2="";
$department2="";
$line2="";
if(isset($_POST['Search'])){
$name = $_POST['name'];
$objQuery=mysql_query("SELECT * FROM persondata WHERE name LIKE '%$name%'");
while($row = mysql_fetch_array($objQuery)){
$name2=$row['name'];
$id_person2=$row['id_person'];
$position2=$row['position'];
$section2=$row['section'];
$department2=$row['department'];
$line2=$row['line'];
}
if(isset($_POST['rad_Leave'])){
$id_person = $_POST['id_person'];
$position = $_POST['position'];
$section = $_POST['section'];
$department = $_POST['department'];
$line = $_POST['line'];
$typeleave = $_POST['rad_Leave'];
$because1 = $_POST['because1'];
$because2 = $_POST['because2'];
$because5 = $_POST['because5'];
$lstDate = $_POST['lstDate'];
$lstMonth = $_POST['lstMonth'];
$lstYear = $_POST['lstYear'];
$lstToDate = $_POST['lstToDate'];
$lstToMonth = $_POST['lstToMonth'];
$lstToYear = $_POST['lstToYear'];
$time = $_POST['time'];
$toTime = $_POST['toTime'];
$totalDay=$_POST['totalDay'];
$totalHrs=$_POST['totalHrs'];
$contactme=$_POST['contactme'];
$tel=$_POST['tel'];
$dateWrite=$_POST['dateWrite'];
$sup_comment=$_POST['sup_comment'];
if($id_person2==$id_person) {
$updateData ="UPDATE persondata SET name='$name',position='$position',section='$section',department='$department',
line='$line'WHERE id_person='$id_person'";
}
else {
mysql_query("INSERT INTO chkarnchang.persondata(id,name,id_person,position,section,department,line)
VALUES('','$name','$id_person','$position','$section','$department','$line')");
mysql_query("INSERT INTO chkarnchang.leaves(id_person,typeLeave,leaveBecause,lstDate,lstMonth,lstYear,
lstToDate,lstToMonth,lstToYear,time,toTime,totalDay,totalHrs,contactme,tel,dateWrite,sup_comment)
VALUES($id_person,$typeLeave,$leaveBecause,$lstDate,$lstMonth,$lstYear,$lstToDate,
$lstToMonth,$lstToYear,$time,$totime,$totalDay,$totalHrs,$contactme,$tel,$dateWrite,$sup_comment)")or die(mysql_error());
}
}
}
?>
โค๊ดใน Dreamweaver ครับ (จะเห็นว่าในโค๊ดข้างล่าง นี้ยังมีเงื่อนไขอีกเยอะที่ยังไม่ได้เขียนโค๊ด php ใส่ แต่ตอนนี้เอาแค่ให้ update ให้ Insert ได้ ก็พอครับ )
Tag : PHP, MySQL, HTML/CSS, JavaScript, Action Script, Windows

|
|
 |
 |
 |
 |
Date :
2015-03-25 15:04:22 |
By :
conchidah |
View :
894 |
Reply :
6 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คำสั่ง SQL ไม่เว้นวรรคเลยครับ ตัวอย่าง
Code (PHP)
$updateData ="UPDATE persondata SET name='$name',position='$position',section='$section',department='$department',
line='$line'WHERE id_person='$id_person'";
ใหม่
line='$line' WHERE id_person='$id_person'";
ที่เหลือไปไล่แก้ดูเผื่อได้ครับ
|
ประวัติการแก้ไข 2015-03-25 16:07:47
 |
 |
 |
 |
Date :
2015-03-25 16:06:42 |
By :
mee079 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ใช้แท็กครอบไว้หน่อยก็ดีครับอ่านจนลายตายละ
|
 |
 |
 |
 |
Date :
2015-03-25 16:12:28 |
By :
LAGO |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ให้ลอง echo ตรวจสอบการทำงาน
จุดที่ 1
Code (PHP)
if(isset($_POST['rad_Leave'])){
echo "<br>ส่ง rad_Leave มาแล้วนะ";
จุดที่ 2
Code (PHP)
if($id_person2==$id_person) {
echo "<br>รหัส id_person2($id_person2) = ($id_person)id_person ด้วยแหละ UPDATE เลย";
$updateData ="UPDATE persondata SET name='$name',position='$position',section='$section',department='$department',
line='$line'WHERE id_person='$id_person'";
//จากนั้นก็ echo $updateData เอาไปลองรันใน phpMyAdmin ว่า error ไหม?
echo $updateData;
|
 |
 |
 |
 |
Date :
2015-03-25 16:39:04 |
By :
{Cyberman} |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คำสั่ง $updateData ='update ....'; เห็นแต่ statement
แต่ไม่เห็น คำสั่ง mysql_query( $updateData );
ส่วนคำสั่ง insert มีแจ้ง error อะไรมาบ้างครับ
|
 |
 |
 |
 |
Date :
2015-03-25 18:17:57 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณทุกท่านนะครับที่ช่วยไข
ผมลองทำตามคำแนะนำของ ทุกคนแล้วนะครับ แต่ยังไม่สำเรํจครับ พิจารณาดูทุกคนก็แนะนำได้ถูกจุดอยุ่นาา!!
ไล่ดูไปมา พอมองเห็นข้อผิดพลาดแล้วครับ
สงสัย ผมเรียงชุดคำสั่งต่างๆ ผิดลำดับแน่เลย ขอลองแก้ดูก่อนนะครับ
ได้ ไม่ได้ยังงัย เดี๋ยวมาแจ็งครับ
|
 |
 |
 |
 |
Date :
2015-03-26 11:42:17 |
By :
conchidah |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แฮ่ๆ ขอรบกวนผู้รู้อีกรอบนะครับ มือใหม่อย่างผม หืดขึ้นคอเลย แก้ปัญหาไม่ตก
ลอง echo ตามจุดต่างๆที่แนะนำมา ดูแล้ว ตัวแปรก็รับค่าได้ปรกติครับ แต่ยังบันทึกลงฐานข้อมูลไม่ได้เลย
**โค๊ดล่าสุดครับ หรือท่านผู้รู้อยากดูส่วนไหนเพิ่มเติม บอกมาเลยครับ ผมจะโพสต์ให้ครับ **
Code (PHP)
<?php
include"connect.php" //เรียกใช้การเชื่อมต่อข้อมูลจากไฟล์ connect.php
?>
<?php
mysql_select_db("$db_name") or die("no database");
mysql_query("SET NAMES utf8");
$name2 ="";
$id_person2="";
$position2="";
$section2="";
$department2="";
$line2="";
if(isset($_POST['btnSearch'])){
$id_person = $_POST['id_person'];
$name = $_POST['name'];
$position = $_POST['position'];
$section = $_POST['section'];
$department = $_POST['department'];
$line = $_POST['line'];
$sql=mysql_query("SELECT * FROM persondata WHERE name LIKE '%$name%'");
while($row = mysql_fetch_array($sql)){
$id_person2=$row['id_person'];
$name2=$row['name'];
$position2=$row['position'];
$section2=$row['section'];
$department2=$row['department'];
$line2=$row['line'];
}
$typeleave = $_POST['rad_Leave'];
$because1 = $_POST['because1'];
$because2 = $_POST['because2'];
$because5 = $_POST['because5'];
$lstDate = $_POST['lstDate'];
$lstMonth = $_POST['lstMonth'];
$lstYear = $_POST['lstYear'];
$lstToDate = $_POST['lstToDate'];
$lstToMonth = $_POST['lstToMonth'];
$lstToYear = $_POST['lstToYear'];
$time = $_POST['time'];
$toTime = $_POST['toTime'];
$totalDay=$_POST['totalDay'];
$totalHrs=$_POST['totalHrs'];
$contactme=$_POST['contactme'];
$tel=$_POST['tel'];
$dateWrite=$_POST['dateWrite'];
$sup_comment=$_POST['sup_comment'];
if($id_person2 == $id_person){
$updateData ="UPDATE persondata SET name='$name', position='$position', section='$section',
department='$department', line='$line' WHERE id_person='$id_person'";
mysql_query($updateData);
echo $id_person2.':'.$id_person; //ทดสอบ ดูค่าจากตัวแปร รับค่าได้ปรกติ
}else {
mysql_query("INSERT INTO chkarnchang.persondata(id,id_person,name,position,section,department,line)
VALUES('','$id_person','$name','$position','$section','$department','$line')");
mysql_query("INSERT INTO chkarnchang.leaves(id,typeLeave,leaveBecause,lstDate,lstMonth,lstYear,
lstToDate,lstToMonth,lstToYear,time,toTime,totalDay,totalHrs,contactme,tel,dateWrite,sup_comment,id_person)
VALUES('','$typeLeave','$leaveBecause','$lstDate','$lstMonth','$lstYear','$lstToDate','$lstToMonth','$lstToYear',
'$time','$totime','$totalDay','$totalHrs','$contactme','$tel','$dateWrite','$sup_comment','$id_person')")or die(mysql_error());
}
}
|
ประวัติการแก้ไข 2015-03-27 19:25:17
 |
 |
 |
 |
Date :
2015-03-27 19:16:32 |
By :
conchidah |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|