|
 |
|
สอบถามเรื่อง บันทึก และ อับเดท พร้อมกัน ข้อมูลเป็น array บางฟิลอับเดทผิด |
|
 |
|
|
 |
 |
|
อับเดท ฟิล 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 :
568 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ต้องตรวจสอบกับ html ด้วยครับ กำหนดรูปแบบ from ยังไง
|
 |
 |
 |
 |
Date :
2018-10-22 20:05:00 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<form action='x.php' method='post' name="form" onsubmit="doSubmit(this)">
<br style="clear:both" />
<table width="900">
<tr>
<td width="126" >name</td>
<td width="758"> <input name="name" type="text" id="name" size="12" value=""/></td>
</tr>
</table>
<br />
<table id="summaryTable">
<tr>
<td width="109">stor_id</td>
<td width="176">stor_id_sub</td>
<td width="176">pro</td>
<td width="130">rest</td>
<td width="145">send</td>
<td width="142">price</td>
<?php
$numInput = 15; //จำนวนแถวกรอกข้อมูล
for($i=1;$i<=$numInput;$i++){
?>
</tr>
<tr>
<td> <input type="text" name="stor_id[]" class="keyword" id="stor_id<?php echo $i ?>" size="15" inputID="<?php echo $i ?>">
<ul class="show_list" id="name_list_<?php echo $i ?>"></ul>
<div id="hint"></div></td>
<td><input name="stor_id_sub[]" type="text" id="stor_id_sub<?php echo $i ?>" value="" size="2" /></td>
<td><input type="text" name="pro[]" id="pro<?php echo $i ?>" size="50"></td>
<td><input type="text" name="rest[]" id="rest<?php echo $i ?>" value="" size="5"></td>
<td><input type="text" name="send[]" id="id1<?php echo $i ?>" onkeyup="calcfunc(<?php echo $i ?>)" onchange="chk_value(<?php echo $i ?>)" value="" size="5" autocomplete=off /></td>
<td><input type="text" id="id2<?php echo $i ?>" name="price[]" size="5" onkeyup="calcfunc(<?php echo $i ?>)" value="" autocomplete=off /></td>
</tr>
<?php } ?>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
<input type="submit" name="btn_submit" id="process" value="submit" onclick="document.all.save.disabled='true'">
</form>
|
ประวัติการแก้ไข 2018-10-23 10:14:07 2018-10-23 10:15:22 2018-10-23 10:15:51
 |
 |
 |
 |
Date :
2018-10-23 10:05:49 |
By :
sawmon |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
name="pro[<?=$id?>]" พยายาม ใส่ index เข้าไปใน name ด้วย จะช่วยให้กำหนด index ได้ชัดเจน
<input type="submit" name="btn_submit" id="process" value="submit" onclick="document.all.save.disabled='true'">
เปลี่ยน type submit เป็น button
แล้วจะทำอะไรต่อก็ว่ากันไป ใน onclick
onclick="document.all.save.disabled='true'; this.form.submit()"
|
 |
 |
 |
 |
Date :
2018-10-23 13:35:37 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|