|  |  | 
          
            | อับเดท ฟิล  stor_id ผิด นานๆ จะมีผิด เลยสงสัยว่าเกิดจากอะไร
 
 Code (PHP)
 
 <?php
$_POST['name'];
foreach($_POST['stor_id'] as $key => $stor_id)
{
$_POST['stor_id'][$key];
$_POST['stor_id_sub'][$key];
$_POST['pro'][$key];
$_POST['rest'][$key];
$_POST['send'][$key];
$_POST['price'][$key];
$sum_sum[$key]=$_POST['rest'][$key] - $_POST['send'][$key];// จำนวน - จำนวนส่ง = คงเหลือ
$stor_id=$_POST['stor_id'][$key];
// inser A ถ้า ไม่ว่าง ให้บันทึก
if($_POST['pro'][$key] != ""){
$insert="INSERT  IGNORE  INTO `A` (id , name , stor_id , stor_id_sub , pro , mem , rest , send , price)
VALUES ('','$name' 
, '{$_POST['stor_id'][$key]}' 
, '{$_POST['stor_id_sub'][$key]}' 
, '{$_POST['pro'][$key]}' 
, '{$_POST['sum_sum'][$key]}' 
, '{$_POST['rest'][$key]}'
, '{$_POST['send'][$key]}'
, '{$_POST['price'][$key]}' )";
$result=mysqli_query($conn,$insert);
if($result){//ถ้าบันทึกเสร็จให้อัปเดท ตาราง B ทันที (อับเดทจำจวนคงเหลือทันที)
foreach($_POST['stor_id'] as $key => $stor_id){
$_POST['rest'][$key];
$_POST['send'][$key];
$sum_sum[$key]=$_POST['rest'][$key] - $_POST['send'][$key];// จำนวน - จำนวนส่ง = คงเหลือ
$stor_id=$_POST['stor_id'][$key];
//อับเดทจำนวนคงเหลือ ในตาราง B (num_b)
$sqq_up="update   `B`    SET    num_b='$sum_sum[$key]'    
WHERE   stor_id='$stor_id'";
$qu_up=mysqli_query($conn,$sqq_up);
if($qu_up){
mysqli_commit($conn);
al("success!!");
redi3("add.php");
     }//82
   }//72
}else{
echo mysqli_error($conn);
mysqli_rollback($conn);
al("not success!!");
redi3("javascript:history:back();");
		}
	}
}
?>
 
 
 Tag : PHP, MySQL, HTML, HTML5, Ajax, jQuery
 
 
 |  
            | 
 ประวัติการแก้ไข
 2018-10-22 16:16:11
 |  
            | 
              
                |  |  |  |  
                |  | 
                    
                      | Date :
                          2018-10-22 16:14:01 | By :
                          sawmon | View :
                          639 | Reply :
                          3 |  |  |  
                |  |  |  |  |  
            |  |  
		            |  |