我正在尝试向数据库中插入超过150行,但是仅91行发生了发布请求,并且控制台日志显示内部服务器错误
插入91行后,出现错误
您的SQL语法有误;检查与您的MySQL服务器版本相对应的手册,以在第1行的’‘附近使用正确的语法
我的HTML表格
<form id="mySpan4" style="display: block;"> <table class="fixed_headers"><tbody> <!-- SKIPPED TO OCC 90 Showing only 90 to 94 --> </tr><tr> <td>PRASAD D R <input type="hidden" name="student[90]" value="PRASAD D R"><input type="hidden" name="Reg[90]" value="13KQC31170"><input type="hidden" name="schoolid[90]" value="FT001"><input type="hidden" name="section[90]" value="A"><input type="hidden" name="standard[90]" value="III BCOM"><input type="hidden" name="Subject[90]" value="COM-42"><input type="hidden" name="date1[90]" value="16-01-07 00:00:00"><input type="hidden" name="UserType[90]" value="STUDENT"><input type="hidden" name="Userid[90]" value="admin"><input type="hidden" name="date_user_submitted[90]" value="2016-01-07 03:51:45 pm"></td> <td><input id="radio01[90]" name="present[90]" type="radio" value="Present"><label for="radio01[90]"><span></span></label></td> <td><input id="radio02[90]" name="present[90]" type="radio" value="Absent"><label for="radio02[90]"><span></span></label></td> <td><input id="radio03[90]" name="present[90]" type="radio" value="Leave"><label for="radio03[90]"><span></span></label></td> </tr><tr> <td>PRASAD K T <input type="hidden" name="student[91]" value="PRASAD K T"><input type="hidden" name="Reg[91]" value="13KQC31171"><input type="hidden" name="schoolid[91]" value="FT001"><input type="hidden" name="section[91]" value="A"><input type="hidden" name="standard[91]" value="III BCOM"><input type="hidden" name="Subject[91]" value="COM-42"><input type="hidden" name="date1[91]" value="16-01-07 00:00:00"><input type="hidden" name="UserType[91]" value="STUDENT"><input type="hidden" name="Userid[91]" value="admin"><input type="hidden" name="date_user_submitted[91]" value="2016-01-07 03:51:45 pm"></td> <td><input id="radio01[91]" name="present[91]" type="radio" value="Present"><label for="radio01[91]"><span></span></label></td> <td><input id="radio02[91]" name="present[91]" type="radio" value="Absent"><label for="radio02[91]"><span></span></label></td> <td><input id="radio03[91]" name="present[91]" type="radio" value="Leave"><label for="radio03[91]"><span></span></label></td> </tr><tr> <td>PRASANNA B <input type="hidden" name="student[92]" value="PRASANNA B"><input type="hidden" name="Reg[92]" value="13KQC31172"><input type="hidden" name="schoolid[92]" value="FT001"><input type="hidden" name="section[92]" value="A"><input type="hidden" name="standard[92]" value="III BCOM"><input type="hidden" name="Subject[92]" value="COM-42"><input type="hidden" name="date1[92]" value="16-01-07 00:00:00"><input type="hidden" name="UserType[92]" value="STUDENT"><input type="hidden" name="Userid[92]" value="admin"><input type="hidden" name="date_user_submitted[92]" value="2016-01-07 03:51:45 pm"></td> <td><input id="radio01[92]" name="present[92]" type="radio" value="Present"><label for="radio01[92]"><span></span></label></td> <td><input id="radio02[92]" name="present[92]" type="radio" value="Absent"><label for="radio02[92]"><span></span></label></td> <td><input id="radio03[92]" name="present[92]" type="radio" value="Leave"><label for="radio03[92]"><span></span></label></td> </tr><tr> <td>PRASANNAKUMAR K <input type="hidden" name="student[93]" value="PRASANNAKUMAR K"><input type="hidden" name="Reg[93]" value="13KQC31173"><input type="hidden" name="schoolid[93]" value="FT001"><input type="hidden" name="section[93]" value="A"><input type="hidden" name="standard[93]" value="III BCOM"><input type="hidden" name="Subject[93]" value="COM-42"><input type="hidden" name="date1[93]" value="16-01-07 00:00:00"><input type="hidden" name="UserType[93]" value="STUDENT"><input type="hidden" name="Userid[93]" value="admin"><input type="hidden" name="date_user_submitted[93]" value="2016-01-07 03:51:45 pm"></td> <td><input id="radio01[93]" name="present[93]" type="radio" value="Present"><label for="radio01[93]"><span></span></label></td> <td><input id="radio02[93]" name="present[93]" type="radio" value="Absent"><label for="radio02[93]"><span></span></label></td> <td><input id="radio03[93]" name="present[93]" type="radio" value="Leave"><label for="radio03[93]"><span></span></label></td> </tr><tr> <td>PREETHI C R <input type="hidden" name="student[94]" value="PREETHI C R"><input type="hidden" name="Reg[94]" value="13KQC31175"><input type="hidden" name="schoolid[94]" value="FT001"><input type="hidden" name="section[94]" value="A"><input type="hidden" name="standard[94]" value="III BCOM"><input type="hidden" name="Subject[94]" value="COM-42"><input type="hidden" name="date1[94]" value="16-01-07 00:00:00"><input type="hidden" name="UserType[94]" value="STUDENT"><input type="hidden" name="Userid[94]" value="admin"><input type="hidden" name="date_user_submitted[94]" value="2016-01-07 03:51:45 pm"></td> <td><input id="radio01[94]" name="present[94]" type="radio" value="Present"><label for="radio01[94]"><span></span></label></td> <td><input id="radio02[94]" name="present[94]" type="radio" value="Absent"><label for="radio02[94]"><span></span></label></td> <td><input id="radio03[94]" name="present[94]" type="radio" value="Leave"><label for="radio03[94]"><span></span></label></td> </tr><tr> <td>RADHA H N <input type="hidden" name="student[95]" value="RADHA H N"><input type="hidden" name="Reg[95]" value="13KQC31179"><input type="hidden" name="schoolid[95]" value="FT001"><input type="hidden" name="section[95]" value="A"><input type="hidden" name="standard[95]" value="III BCOM"><input type="hidden" name="Subject[95]" value="COM-42"><input type="hidden" name="date1[95]" value="16-01-07 00:00:00"><input type="hidden" name="UserType[95]" value="STUDENT"><input type="hidden" name="Userid[95]" value="admin"><input type="hidden" name="date_user_submitted[95]" value="2016-01-07 03:51:45 pm"></td>
JS
$(document).ready(function() { $('#mySpan4').submit(function(e) { $.ajax({ type: 'post', url: 'http://localhost/demo_TeacherApp/attendence_submit.php', // you should not use absolute addresses, with http:// . only relative paths data: $('#mySpan4').serialize(), success: function(data) { // log $sql string //<!-- $('#log').html(data); --> } }); // prevents the form from really submitting through the normal way e.preventDefault(); return false; }) });
的PHP
<?php $servername = "localhost"; $username = "root"; $password = "xxxx"; $dbname = "xxxxx"; $conn = new mysqli($servername, $username, $password, $dbname); // ** insert data in to data base ** // $sql = "INSERT INTO attendance_master (StudentFirstName,AttendanceStatus,StudentRegID,SchoolID,Section,Standard,Subjects,AttendanceDate,UserType,Attendence_taken_by,Attendence_taken_date) VALUES "; // **hear the data or is calculated using student as a string the number of student names are passed the same number of data is inserted in to data base ** // foreach($_POST['Reg'] as $i=>$student) { // ** so the data is inserted in to data base ** // $sql .= sprintf("%s ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')" , ($i==0 ? '' : ',') // ** data from Ajax ** // , mysqli_real_escape_string($conn, trim($_POST['student'][$i])) , mysqli_real_escape_string($conn, trim($_POST['present'][$i])) , mysqli_real_escape_string($conn, trim($_POST['Reg'][$i])) , mysqli_real_escape_string($conn, trim($_POST['schoolid'][$i])) , mysqli_real_escape_string($conn, trim($_POST['section'][$i])) , mysqli_real_escape_string($conn, trim($_POST['standard'][$i])) , mysqli_real_escape_string($conn, trim($_POST['Subject'][$i])) , mysqli_real_escape_string($conn, trim($_POST['date1'][$i])) , mysqli_real_escape_string($conn, trim($_POST['UserType'][$i])) , mysqli_real_escape_string($conn, trim($_POST['Userid'][$i])) , mysqli_real_escape_string($conn, trim($_POST['date_user_submitted'][$i])) ); } // ** on success full function ** // if ($conn->query($sql)) { echo $sql;// **can do any thing to recognise if the data is inserted if this gives the out put then the data is shorly inserted in to data base ** // } ?>
我注意到在您的HTML中,索引从事件92跳到事件146。
同样,隐藏字段的PRASANNA B发生次数为92,但单选按钮的发生次数为145。
PRASANNA B
看起来当您创建此表单时,索引策略出了点问题!这可能可以解释为什么在将第92行加载到数据库时一切都开始出错
</tr><tr> <td>PRASANNA B <input type="hidden" name="student[92]" value="PRASANNA B"><input type="hidden" name="Reg[92]" value="13KQC31172"><input type="hidden" name="schoolid[92]" value="FT001"><input type="hidden" name="section[92]" value="A"><input type="hidden" name="standard[92]" value="III BCOM"><input type="hidden" name="Subject[92]" value="COM-38"><input type="hidden" name="date1[92]" value="16-01-07 00:00:00"><input type="hidden" name="UserType[92]" value="STUDENT"><input type="hidden" name="Userid[92]" value="admin"><input type="hidden" name="date_user_submitted[92]" value="2016-01-07 03:37:22 pm"></td> <td><input id="radio01[145]" name="present[145]" type="radio" value="Present"><label for="radio01[145]"><span></span></label></td> <td><input id="radio02[145]" name="present[145]" type="radio" value="Absent"><label for="radio02[145]"><span></span></label></td> <td><input id="radio03[145]" name="present[145]" type="radio" value="Leave"><label for="radio03[145]"><span></span></label></td> </tr><tr>
好的,现在我们已经驳斥了这个想法! 让我们从头开始。
PHP有几个可能会超出的参数,即
post_max_size 这意味着脚本不会接收所有的post数组
max_input_vars 限制<input>脚本将接受的变量数量
<input>
由于您至少有 1950个 输入变量,我知道这可能是第一个要检查的变量。因此,请在您的php.ini文件中查找这两个参数,然后让我知道它们是什么。
php.ini
因此,从您的评论 看来max_input_vars = 1000,此脚本至少具有 1950个 变量似乎还不够。这肯定可以解释您得到的错误!我认为默认值为1000,这就是为什么要使用注释形式。
max_input_vars = 1000
因此,为了安全起见,请修改php.iniand make max_input_vars = 2500,;当然不加评论。
max_input_vars = 2500
;
*进行以下更改后, *别忘 了重新启动Apachephp.ini