|
 |
แก้ไขโค๊ดตรวจสอบโค๊ดphpการเพิ่มข้อมูลจำนวนสสินค้าจากตารางสู่อีกตาราง |
|
 |
|
|
 |
 |
|
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
for($i=0; $i <count($_POST['prdno'])&&$_POST['prdno'][$i]!="";$i++){
$insertSQL = sprintf("INSERT INTO products_stock (username, product_on, product_time) VALUES (%s, %s, %s)",
GetSQLValueString($_POST['userorder'], "text"),
GetSQLValueString($_POST['prdno'][$i], "text"),
GetSQLValueString($_POST['item'][$i], "int"));
mysql_select_db($database_chuchai, $chuchai);
$Result1 = mysql_query($insertSQL, $chuchai) or die(mysql_error());
$dwSQL = "Update products Set item=item+".$_POST['item'][$i]."Where id=".$_POST['prdno'][$i]." Limit 1";
mysql_query($dwSQL);
}
ต้องการให้เพิ่มข้อมูลลงตารางโปรดักสินค้าเพิ่มขึ้น ***** รันแล้วข้อมูลจำนวนสินค้าไม่เพิ่มขึ้น*****
เพิ่มแต่ตารางบันถึงผู้เพิ่มสินค้า
Tag : MySQL, Ms SQL Server 2005, Appserv
|
|
 |
 |
 |
 |
Date :
2020-04-26 21:45:08 |
By :
1069053330151535 |
View :
731 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP 5.4)
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { // เช็คเงื่อนไขในลูป
for($i=0; $i <count($_POST['prdno'])&&$_POST['prdno'][$i]!="";$i++){
$insertSQL = sprintf("INSERT INTO products_stock (username, product_on, product_time) VALUES (%s, %s, %s)",
GetSQLValueString($_POST['userorder'], "text"),
GetSQLValueString($_POST['prdno'][$i], "text"),
GetSQLValueString($_POST['item'][$i], "int"));
mysql_select_db($database_chuchai, $chuchai); // ตรวจสอบตัวแปร
$Result1 = mysql_query($insertSQL, $chuchai) or die(mysql_error());
$dwSQL = "Update products Set item=item+".$_POST['item'][$i]."Where id=".$_POST['prdno'][$i]." Limit 1";
mysql_query($dwSQL);
}
อะไรคือ ตารางโปรดัก, ข้อมูลจำนวนสินค้า, ตารางบันถึงผู้เพิ่มสินค้า etc.
ไม่มีใครรู้กับคุณว่าคุณใช้ตัวแปรชื่ออะไรบ้าง
กรณีที่กวาดด้วยสายตาแล้วมั่นใจว่าไม่ได้พิมผิด ลองศึกษาวิธี debug ใน php ดูครับ
เบื้องต้นตรวจสอบการส่งค่ารับค่าระหว่างตัวแปร และ/หรือ ฟังก์ชัน
ด้วย echo, print_r, var_dump
ถ้าพอมีเวลา ศึกษาเพิ่มเติมวิธีใช้ DBG (เหมาะสำหรับ php 4, 5)
http://www.php-debugger.com/dbg/
หรือมองการไกลเปลี่ยนไปใช้ mysqli library แทน แล้วดูวิธีใช้ Xdebug
http://xdebug.org/
|
 |
 |
 |
 |
Date :
2020-04-27 11:43:37 |
By :
PhrayaDev |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 02
|