2019-02-04 21:51
浏览 76

PHP表单提交 - 语法错误

I have an HTML form that is fairly simple:


<form method="POST" id="form-1" name="form-1">
      <input type="text" name="fm1q1">
      <input type="number" name="fm1q1-score">
      <input type="text" name="fm1q2">
      <input type="number" name="fm1q2-score">
      <input type="text" name="fm1q3">
      <input type="number" name="fm1q3-score">
      <input type="text" name="fm1q4">
      <input type="number" name="fm1q4-score">
      <input type="text" name="fm1q5">
      <input type="number" name="fm1q5-score">
   <button type="submit" name="submit">SUBMIT</button>

I'm using a simple Ajax call:

$('#form-1').on('submit', function(e){
        type:   'POST',
        url:    'submitForm.php',
        data:   $(this).serialize(),
        success: function(data){
        error: function(xhr, ajaxOptions, thownError){

The PHP that inserts the form data into a MySQL DB Table is like this:

require "config.php"; // Contains all my connection information 
$answers = array($_POST['fm1q1'], $_POST['fm1q2'], $_POST['fm1q3'], $_POST['fm1q4'], $_POST['fm1q5']);
$scores = array($_POST['fm1q1-score'], $_POST['fm1q2-score'], $_POST['fm1q3-score'], $_POST['fm1q4-score'], $_POST['fm1q5-score']);

for ($i = 0; $i < 5; $i++) { 
   $sql = "INSERT INTO table_1 (answer, score) VALUES ('$answers[$i]', '$scores[$i]')";
   $result = mysqli_query($conn, $sql);
   if (!$conn->query($result) === TRUE) {
      echo "Error: " . $sql . "--" . $conn->error. "


The problem I'm running into is that my Developer Tools say I have a Syntax error in the $sql= line, but I can't see what's wrong.

Error: INSERT INTO table_1 (answer, score) VALUES ('test', '123')--You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '1' at line 1

2条回答 默认 最新

相关推荐 更多相似问题