|
 |
|
ทำการเพิ่มข้อมูลแล้ว ไม่ยอมเช็คเงื่อนไข และ ตรวจสอบ ค่า List Manu ทั้ง 2 ค่า |
|
 |
|
|
 |
 |
|
ผมมีเรื่องปรึกษาหน่อยครับ ตอนนี้เพื่อนผมกำลังทำโปรเจ็คจบครับ และติดปัญหาในการเพิ่มข้อมูล โดยเช็คเงื่อนไขครับ

ภาพแรกเป็นข้อมูลที่อยู่ใน ตาราง numproduct ซึ่งประกอบไปด้วยฟิวด์ 4 ค่า คือ Product_ID, Lens_ID, Category_ID และ Number

ภาพนี้เมื่อทำการกดปุ่มเพิ่มข้อมูลจะเข้ามายังหน้า insert_addinfor.php ซึ่งเป็นหน้าเพิ่มข้อมูล โดยมีเงื่อนไขว่า ถ้าเลือกเมนู se_lens ตรงกับเมนู se_cate ในตาราง numproduct จะไม่สามารถเพิ่มข้อมูลได้ และจากฟ้องข้อความพร้อมรีเฟสกลับไปยังหน้า show_add.php แต่ถ้าเงื่อนไข ถ้าเลือกเมนู se_lens ไม่ตรงกับ เมนู se_cate ในตาราง numproduct ก็จะทำการเพิ่มข้อมูลมา 1 แถว และจะรีเฟสไปยังหน้า show_add.php
สำหรับหน้า code ครับผม
Code (PHP)
include ("config_db.php");
$strSQL = "INSERT INTO numproduct (Lens_ID,Category_ID,Number)";
$strSQL .= "VALUES ('$_POST[se_lens]', '$_POST[se_cate]', '$_POST[txtNum]'); ";
$q = "select Lens_ID,Category_ID from numproduct where Lens_ID = '$_POST[se_lens]' and Category_ID = '$_POST[se_cate]' ";
$result = mysql_query($q);
$rs=mysql_fetch_array($result);
if($rs['Lens_ID'] == '$_POST[se_lens]' && $rs['Category_ID'] == '$_POST[se_cate]') {
echo "ระบบทำการเพิ่มข้อมูลเรียบร้อยแล้ว<br>กรุณารอสักครู่<br>";
echo "<meta http-equiv='refresh' content='3;URL= show_add.php' />";
mysql_query( $strSQL , $conn )
or die ("การเพิ่มข้อมูลมีข้อผิดพลาดเกิดขึ้น " . mysql_errno());
}else echo "ข้อมูลซ้ำไม่สามารถเพิ่มข้อมูลได้";
echo "<meta http-equiv='refresh' content='3;URL= show_add.php' />";
ขอบคุณล้วงหน้าที่สละเวลามา ไขข้องใจครับผม
Tag : PHP, MySQL, JavaScript, Windows

|
ประวัติการแก้ไข 2012-08-30 21:25:52 2012-08-30 21:26:13
|
 |
 |
 |
 |
Date :
2012-08-30 21:24:20 |
By :
veeitdata5 |
View :
1199 |
Reply :
9 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จะช่วยซะหน่อยงงคำถามตรงที่
"ถ้าเลือกเมนู se_lens ตรงกับเมนู se_cate ในตาราง numproduct จะไม่สามารถเพิ่มข้อมูลได้"
นี่แหละ
กำลังจะหมายถึง se_lens ตรงกับข้อมูลในฟิลด์ Lens_ID และ se_cate ตรงกับ Category_ID แบบนี้หรือเปล่า
ถ้าใช่ก็แค่
Code (PHP)
$se_lens = $_POST['se_lens'];
$se_cate = $_POST['se_cate'];
$query = mysql_query("SELECT * FROM numproduct WHERE Lens_ID='$se_lens' AND Category_ID='$se_cate' LIMIT 1");
if (mysql_num_rows>0)
{
//ขึ้นข้อความ เซฟไม่ได้ เพราะซ้ำ แล้วสั่ง Redirect
} else {
// ตรงนี้ insert แล้วสั่ง Redirect
}
|
 |
 |
 |
 |
Date :
2012-08-30 21:41:55 |
By :
adaaugusta |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
$strSQL .= "VALUES ('$se_lens', '$se_cate', '$_POST[txtNum]'); ";
ตรง .="VALUES เว้นวรรคให้มันหน่อย ไม่งั้นมันจะติดกันกลายเป็น
"INSERT INTO numproduct (Lens_ID,Category_ID,Number)VALUES ('$se_lens', '$se_cate', '$_POST[txtNum]');
และ ไม่ต้องใส่ semicolon
ก็จะได้เป็น
$strSQL .= " VALUES ('$se_lens', '$se_cate', '$_POST[txtNum]')";
|
 |
 |
 |
 |
Date :
2012-08-30 22:48:12 |
By :
adaaugusta |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
//ลองนี่ดู
include ("config_db.php");
$se_lens = $_POST['se_lens'];
$se_cate = $_POST['se_cate'];
$query = mysql_query("SELECT * FROM numproduct WHERE Lens_ID= '$se_lens' AND Category_ID='$se_cate' LIMIT 1");
$result = mysql_num_rows($query);
if ($result>0)
{
echo "ข้อมูลซ้ำไม่สามารถเพิ่มข้อมูลได้";
echo "<meta http-equiv='refresh' content='3;URL= show_add.php' />";
} else {
$strSQL = "INSERT INTO numproduct (Lens_ID,Category_ID,Number)";
$strSQL .= " VALUES ('$se_lens', '$se_cate', '$_POST[txtNum]') or die (mysql_error())";
exit(0);
echo "ระบบทำการเพิ่มข้อมูลเรียบร้อยแล้ว<br>กรุณารอสักครู่<br>";
echo "<meta http-equiv='refresh' content='3;URL= show_add.php' />";
}
|
 |
 |
 |
 |
Date :
2012-08-31 13:41:37 |
By :
adaaugusta |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 02
|