|
 |
|
งงค่ะมัน insert ข้อมูลลงดาต้าเบสไม่ได้ มีรูป + โค้ด คือนำค่าจากตัวแปรที่่รับมาไปใส่ฟังก์ชัน implode เพื่อใส่คอมม่าเพราะรับค่ามาแบบ checkbox |
|
 |
|
|
 |
 |
|
อันนี้หน้าตาของ form ที่รับข้อมูลค่ะ

อันนี้โค้ดส่วน input ที่เป็น checkbox ที่มีปัญหาค่ะ
<input type="checkbox" name="for[]" id="for[]" value="ปี1" />
</label>ปี1
<label>
<input name="for[]" type="checkbox" id="for[]" value="ปี2" />
</label>
ปี2
<label>
<input name="for[]" type="checkbox" id="for[]" value="ปี3" />
</label>
ปี3
<label>
<input name="for[]" type="checkbox" id="for[]" value="ปี4" />
ปี4<br />
พอลองกรอกข้อมูลแล้วเลือก ติ๊ก check box ตรงชั้นปี เป็น ปี 1 กับ ปี 2 แล้วกด ปุ่ม สร้างแบบประเมิน
แล้วมันแจ้ง error ดังรูปหน่ะค่ะ ไม่รู้ว่าเกิดจากอะไรผิดพลาดตรงไหน เพราะลอง echo ค่าที่รับมาจาก checkbox
(for) แล้วก็พบว่ามีค่า รบกวนผู้เชี่ยวชาญดูให้ทีค่ะ

นี่เป็นโค้ดส่วนบันทึกข้อมูลลงดาต้าเบสค่ะ
if(isset($HTTP_POST_VARS['Submit'])&&($HTTP_POST_VARS['Submit']=="สร้างแบบประเมิน")){
$for_real = implode(",",$for); // นำค่าใน $for ใส่ ,
echo ($for_real."rakdunk");
$query = "SELECT project_id FROM project WHERE project_id like '$project_id'";
$rsCheck = mysql_query($query, $connproject) or die(mysql_error());
$total = mysql_num_rows($rsCheck);
if($total<>0)
{
msg("โครงการนี้ได้จัดทำแบบประเมินแล้วค่ะ");
}
$insertSQL = "INSERT INTO project(project_id,project_name,place,date_make,for,academic_year,
start_evaluation,end_evaluation) VALUES('$project_id','$project_name','$place', '$date_make','$for_real',
'$academic_year','$start_evaluation','$end_evaluation')";
$Result = mysql_query($insertSQL, $connproject) or die(mysql_error());
if($Result<>0)
{
echo "สร้างแบบประเมินเรียบร้อยแล้วค่ะ";
}
}
*** ชนิดข้อมูลของฟิวด์ for ในดาต้าเบสคือ varchar ค่ะ ขอบคุณนะค่ะ
Tag : PHP, MySQL, HTML/CSS

|
|
 |
 |
 |
 |
Date :
2010-11-19 18:45:55 |
By :
nuie |
View :
995 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
for เป็น reserved words ครับ
เปลี่ยนชื่อฟิลด์ หรือไม่งั้นก็ใส่ `for`
|
 |
 |
 |
 |
Date :
2010-11-19 19:47:04 |
By :
PlaKriM |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ได้แล้วค่ะ ตามที่คุณ PlaKriM บอกเลย อ่านมาเยอะ แต่ดันลืม อิอิ
|
 |
 |
 |
 |
Date :
2010-11-21 11:11:00 |
By :
nuie |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|