繁体   English   中英

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')

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM