|
 |
|
ใช้ while เก็บข้อมูลลงฐานข้อมูล แต่ข้อมูลไม่เก็บ และ ไม่มีแจ้ง error |
|
 |
|
|
 |
 |
|
Code (PHP)
<?php
session_start();
$sid=session_id();
include("../inc/dbconn.inc.php");
$priceall=$_POST['txtprice'];
$user_id=$_SESSION['user_id'];
$sql = "SELECT * FROM cart
WHERE sess_id='$sid'";
$result = mysql_query($sql)or die(mysql_error());
$reserve_id = mysql_insert_id();
//นำข้อมูลที่อ่านมาจากตาราง cart และค่า id ของลูกค้า ไปเพิ่มลงในตาราง reserv
while($cart = mysql_fetch_array($result)) {
$grooming_id=$cart['grooming_id'];
$date_use=$cart['date_use'];
$user_id=$cart['user_id'];
$pet_id =$cart['pet_id'];
$time =$cart['time'];
$sql2 = "INSERT INTO reserve_grooming VALUES
('','.$reserve_id.','$grooming_id',NOW(),'$date_use','$time','$priceall','$user_id','$pet_id')";
@mysql_query($sql2)or die (mysql_error());
}
$sql1 = "INSERT INTO reserve VALUES
('.$reserve_id.','0',NOW(),'$priceall','$user_id','0')";
$query=mysql_query($sql1)or die(mysql_error());
//หลังย้ายข้อมูล ให้ลบข้อมูลในตารง cart ทิ้งไป
$SQL3 = "DELETE FROM cart
WHERE user_id = '".$_SESSION['user_id']."' ";
@mysql_query($SQL3)or die (mysql_error());
session_destroy();
echo "ทำการจองเรียบร้อยแล้ว รออนุมัติการจองจากทางร้าน <br>สามารถตรวจสอบได้ที่ <a href=\"status.php\">ตรวจสอบสถานะ</a>";
?>
Tag : PHP

|
ประวัติการแก้ไข 2013-10-10 12:19:13 2013-10-10 12:20:09
|
 |
 |
 |
 |
Date :
2013-10-10 12:05:46 |
By :
ging0o0 |
View :
849 |
Reply :
6 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
systax insert ผิดครับ
Code (PHP)
$sql2 = "INSERT INTO reserve_grooming (Fieldname) VALUES
('','.$reserve_id.','$grooming_id',NOW(),'$date_use','$time','$priceall','$user_id','$pet_id')"; // ชื่อฟิวหายไปครับ
|
 |
 |
 |
 |
Date :
2013-10-10 12:09:00 |
By :
Ex-[S]i[L]e[N]t |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
syntax ไม่ได้ผิดครับ สามารถใช้แบบนี้ได้เหมือนกันในกรณีที่ INSERT ข้อมูลทุกคอลัมน์เรียงตามโครงสร้างตารางเป๊ะๆ
แต่อาจจะผิดตรงที่มี . อยู่ใน sql ครับ ซึ่งอาจจะทำให้ค่าไม่ถูกต้อง พิจารณาจากชื่อตัวแปร ($reserve_id[) แล้ว น่าจะเป็นชนิดตัวเลขเช่น INT
ซึ่งพอมี . อยู่ในค่า ก็จะทำให้ mysql บอกว่าค่านี้ไม่ใช่ตัวเลข และ error ครับ
$sql2 = "INSERT INTO reserve_grooming VALUES
('','.$reserve_id.','$grooming_id',NOW(),'$date_use','$time','$priceall','$user_id','$pet_id')";
@mysql_query($sql2)or die (mysql_error());
}
|
ประวัติการแก้ไข 2013-10-10 12:14:53
 |
 |
 |
 |
Date :
2013-10-10 12:14:07 |
By :
phpinfo() |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองลบ จุด ออกแล้วนะค่ะ ก็ยังไม่ได้ อยู่ดี
แต่พอมานอก while แล้ว ลงฐานข้อมูลได้ค่ะ
(แล้วเราจะใส่จุดทำไมหว่า งงกับตัวเอง เหอะๆ )
|
 |
 |
 |
 |
Date :
2013-10-10 12:31:26 |
By :
ging0o0 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอบความคิดเห็นที่ : 3 เขียนโดย : ging0o0 เมื่อวันที่ 2013-10-10 12:31:26
รายละเอียดของการตอบ ::
งั้นแสดงว่าโค้ดใน while มันไม่ทำงานครับ เพราะ sql ที่สั่งไปตอนแรก มันไม่เจอข้อมูลครับ
Code (PHP)
<?php
session_start();
$sid=session_id();
include("../inc/dbconn.inc.php");
$priceall=$_POST['txtprice'];
$user_id=$_SESSION['user_id'];
$sql = "SELECT * FROM cart
WHERE sess_id='$sid'";
// อาจจะเป็นตั้งแต่ตรงนี้ คือไม่เจอข้อมูล
$result = mysql_query($sql)or die(mysql_error());
$reserve_id = mysql_insert_id();
//นำข้อมูลที่อ่านมาจากตาราง cart และค่า id ของลูกค้า ไปเพิ่มลงในตาราง reserv
// พอไม่เจอข้อมูล mysql_fetch_array() ก็จะให้แถวที่ว่างเปล่ากลับมา ทำให้เงื่อนไขไม่เ็ป็นจริง
// และโค้ดใน while ก็จะไม่ทำงาน
while($cart = mysql_fetch_array($result)) {
$grooming_id=$cart['grooming_id'];
$date_use=$cart['date_use'];
$user_id=$cart['user_id'];
$pet_id =$cart['pet_id'];
$time =$cart['time'];
$sql2 = "INSERT INTO reserve_grooming VALUES
('','.$reserve_id.','$grooming_id',NOW(),'$date_use','$time','$priceall','$user_id','$pet_id')";
@mysql_query($sql2)or die (mysql_error());
}
$sql1 = "INSERT INTO reserve VALUES
('.$reserve_id.','0',NOW(),'$priceall','$user_id','0')";
$query=mysql_query($sql1)or die(mysql_error());
//หลังย้ายข้อมูล ให้ลบข้อมูลในตารง cart ทิ้งไป
$SQL3 = "DELETE FROM cart
WHERE user_id = '".$_SESSION['user_id']."' ";
@mysql_query($SQL3)or die (mysql_error());
session_destroy();
echo "ทำการจองเรียบร้อยแล้ว รออนุมัติการจองจากทางร้าน <br>สามารถตรวจสอบได้ที่ <a href=\"status.php\">ตรวจสอบสถานะ</a>";
?>
|
 |
 |
 |
 |
Date :
2013-10-10 12:38:16 |
By :
phpinfo() |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณมากค่ะ ได้แล้วค่ะ หา where ไม่เจอ เพราะ ไปกำหนดขนาด sesion_id เปน 10 แต่ค่ามันเกิน 10 ค่ะ มันก็เลยไม่ตรงกัน
|
 |
 |
 |
 |
Date :
2013-10-10 13:28:33 |
By :
ging0o0 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 02
|