|
 |
|
insert ข้อมูลเข้าในฐานข้อมูล 2 ตาราง ผ่าน checkbox แล้วไม่เข้าอีกตาราง รบกวนช่วยดูให้หน่อยนะคะ :( |
|
 |
|
|
 |
 |
|
คือว่า มี ตารางอยู่ 2 ตารางคะ
ตาราง room เก็บข้อมูลห้อง
ตาราง equip_room เก็บข้อมูลอุปกรณ์ในห้อง
ตาราง equipment เก็บข้อมูลอุปกรณ์
Code (PHP)
<form action="adroom.php" name="addroom" method="post" onSubmit="return chkdata();">
<input name="txtroom" type="text" id="txtroom" onkeypress=check_number(); size="7" maxlength="7" autocomplete="off">
<?php
$qq="select * From equipment order by equip_name";
$qrr=mysql_query($qq);
while($rs=mysql_fetch_array($qrr)){
?>
<input name="checkGE[<?=$rs['equip_name']?>]" type="checkbox" value="<?=$rs['equip_id']?>"/>
<?php echo $rs['equip_name']."<br><br>";?>
<?php
}
?>
<input name="Submit" type="submit" class="button" value="ตกลง">
อันนี้ดึงอุปกรณ์มาจากฐานข้อมูล มาทำเป็น checkbox อ่ะคะ แล้วตอน POST ไป อยากจะเก็บข้อมูลห้องไว้ room_id, room_name ฯลฯ ไว้ที่ ตาราง room
แล้วเก็บ room_id (อันเดียวกันกะข้างบน) , equip_id (ที่ดึงมาจาก equipment) ไว้ตาราง equip_room อ่ะคะ แต่ไม่เข้าตารางอ่ะคะ ??? T_____T
Code (PHP)
require("../config.php");
setthai();
$new_id =mysql_result(mysql_query("Select Max(substr(room_id,-3))+1 as MaxID from room"),0,"MaxID");
if($new_id==''){
$room_id="R001";
}else{
$room_id="R".sprintf("%03d",$new_id);
}
$query = "insert into room (room_id,room_name,buildNo) values ('$room_id','$txtroom','$build')";
$result = mysql_query($query);
for($i=0;$i<count($_POST["checkGE"]);$i++)
{
if($_POST["checkGE"][$i] != "")
{
$queryE = "insert into equip_room (equip_id,room_id) values ('".$_POST["checkGE"][$i]."','$room_id')";
$objQuery = mysql_query($queryE);
}
}
/// ???? ตรงนี้เลยคะ ไม่รู้ว่าใส่ถูกหรือเปล่า ค๊ะ - -* มีวิธีอื่นแนะนำไหมคะ หรือตกตัวอะไรไปอ่ะคะ ???
}
}
}
mysql_close();
ไม่ขึ้น ERROR แต่ไม่เข้าฐานข้อมูล equip_room เลยค๊า T^T
ขอบพระคุณล่วงหน้านะคะ :)))
Tag : PHP, MySQL

|
ประวัติการแก้ไข 2012-01-01 01:52:06 2012-01-01 01:55:41
|
 |
 |
 |
 |
Date :
2011-12-31 23:06:08 |
By :
Doremeez |
View :
1299 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลอง comment บันทัดนี้ดูนะครับ
Code (PHP)
$reQ = mysql_query($queryE);
แล้วเปลี่ยนเป็น echo $queryE."<br />";
ซึ่งผลลัพธ์น่าจะเป็นคำสั่งคิวรี่ เท่ากับจำนวนที่ถูกโพสเข้ามา ( $_POST['checkGE'] )
ถ้าผลลัพธ์ออกมาถูกต้อง แสดงว่ามีปัญหาที่ขั้นตอนข้างล่างนี้ (ต้องทดลองนะครับ)
Code (PHP)
$reQ = mysql_query($queryE);
ถ้าใช่...ผมคิดว่าน่าจะต้องหาวิธี execute คิวรี่เพิ่มเติม (อาจจะต้องใช้ fetch หรือเปล่าไม่แน่ใจนะครับ)
|
 |
 |
 |
 |
Date :
2011-12-31 23:24:41 |
By :
Songkram |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
- -* กรรมกว่าเก่าเลยคะ มันวนลูป บันทึกข้อมูลซ้ำใน room อ่ะคะ
แต่ไม่เข้า equip_room เลยค๊ะ
T__________________________T
|
 |
 |
 |
 |
Date :
2011-12-31 23:32:35 |
By :
Doremeez |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เข้าแล้วค๊าาาาาาาาาา 555555 สรุปคือ ประสาทเอง เอิ๊กๆๆๆ ไม่ยอมจนได้ อิอิ ดีจัยที่สวดด ^^
จากบรรทัดนี้
Code (PHP)
<input name="checkGE[<?=$rs['equip_name']?>]" type="checkbox" value="<?=$rs['equip_id']?>"/>
เป็นบรรทัดนี้
Code (PHP)
<input type="checkbox" name="checkGE[]" value="<?=$rs['equip_id']?>"/>
หลอนค่าาาาาาาาา :))))
|
 |
 |
 |
 |
Date :
2012-01-01 02:07:38 |
By :
Doremeez |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 03
|