Mysql表中的数据只存储一条记录


Data in Mysql Table only store one record

我有一个mysql数据库,我在其中添加数据到mysql数据库中,但问题是它只存储一条记录,而不是更多。

我的表格结构是

    <?php
    $con =  mysql_connect("example.com","name","password");
    if (!$con)
     {
     die('Could not connect: ' . mysql_error());
     }
     mysql_select_db("surveyipad", $con);
     $response_id=$_POST['response_id'];
     $participant_id=$_POST['participant_id'];

     $question_id=$_POST['question_id'];

     $answer_text=$_POST['answer_text'];

     $answer_option=$_POST['answer_option'];

     $query=("INSERT INTO survey_question_responses (response_id,participant_id,question_id,answer_text,answer_option)
      VALUES ('', '$participant_id','$question_id','$answer_text','$answer_option')");
       mysql_query($query,$con);
       printf("Records inserted: %d'n", mysql_affected_rows());
     echo($response_id)
   ?>

响应id是表中的主键,也设置为自动递增

像这样尝试

$query=("INSERT INTO survey_question_responses (participant_id,question_id,answer_text,answer_option)
      VALUES ('$participant_id','$question_id','$answer_text','$answer_option')");

当您使id字段自动递增时,不要在insert查询中插入它。

将查询写入

INSERT INTO survey_question_responses (participant_id, question_id, answer_text, answer_option)
VALUES ('$participant_id', '$question_id', '$answer_text', '$answer_option')

您还应该解释或发送表格的结构。