php - mysql不会插入5到10个用户同时提交的同一个php表单的所有数据

标签 php mysql bulkinsert

我正在使用 php 表单提交学生费用。如果单个用户提交该表单,一切正常并且数据保存在 MySQL 数据库中。但是如果我使用从5-10 个不同 系统同时,MySQL 只插入两个或三个用户的数据。 我正在为 invoice_id 使用触发器:

CREATE TRIGGER `test_trig` BEFORE INSERT ON `student_fee_transaction_details`
 FOR EACH ROW BEGIN
    SET NEW.inv_no=(SELECT CONCAT(NEW.school_id,'-', SUBSTRING_INDEX( inv_no,  '-', -1 ) +1 ) AS inv_number_new
FROM student_fee_transaction_details
WHERE id IN (SELECT MAX( id ) FROM student_fee_transaction_details WHERE school_id = NEW.school_id
));
END

这是我要插入的 php 代码

insert into student_fee_transaction_details (id,fine_amount,interest_amount,handling_charges,
institute_id,school_id,student_id,class_id,section_id,admission_no,fees_amount,payment_date,
payment_mode,paid_amount,inv_date,inv_ref_no,inv_no,inv_status,session,payment_bank,payment_type,
cheque_dd_no,payment_chanel,fee_due_date,cheque_dd_date,remarks,deposit_bank_id)
values('','$fine_amt','$interest_amt','$hand_charge','$ins_id','$sch_id','$stu_id','$cls_id',
'$sec_id','$adm_no','$total_fee_paid_amt','$pay_dt','Manual','$total_paid_amt','$inv_dt',
'$ref_no','1898776','Invoiced','$session','$bank_nm','$pay_type','$dd_chq_no','web',
'$fee_due_date','$dd_cheq_dt','$swipe_remarks','$deposit_bank')";
 $result_inv_master = $con->query($qry_inv_master); 

最佳答案

只需将您的 id 列设置为 Auto Incremented 并且不要将 id 值作为 '' 传递您的查询。 像这样

insert into student_fee_transaction_details (fine_amount,interest_amount,handling_charges,
institute_id,school_id,student_id,class_id,section_id,admission_no,fees_amount,payment_date,
payment_mode,paid_amount,inv_date,inv_ref_no,inv_no,inv_status,session,payment_bank,payment_type,
cheque_dd_no,payment_chanel,fee_due_date,cheque_dd_date,remarks,deposit_bank_id)
values('$fine_amt','$interest_amt','$hand_charge','$ins_id','$sch_id','$stu_id','$cls_id',
'$sec_id','$adm_no','$total_fee_paid_amt','$pay_dt','Manual','$total_paid_amt','$inv_dt',
'$ref_no','1898776','Invoiced','$session','$bank_nm','$pay_type','$dd_chq_no','web',
'$fee_due_date','$dd_cheq_dt','$swipe_remarks','$deposit_bank')";
 $result_inv_master = $con->query($qry_inv_master); 

修改一下就不会再出现这个问题

关于php - mysql不会插入5到10个用户同时提交的同一个php表单的所有数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45101348/

相关文章:

php - SQL/PHP 创建数据库并加载 .CSV

PHP 5 : What DAL are you using?

php - 给定圆心坐标、半径和扫描角,如何计算圆弧的终点坐标?

php - 获取mysql中的下一条和上一条记录

php - 如何使用PHP限制用户上传图片的大小

PHP变量未定义,但我在函数中设置它们

PHP : How can I synchronize one online sql database with another offline database?

mysql - Mac 10.12 上的错误 : Error installing mysql2: ERROR: Failed to build gem native extension.

sql - 批量插入 - UNIX 文件的行终止符 + "\l"行终止符

jsf - 使用jpa批量插入eclipselink