我有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是表中的主键,也设置为自动增量
答案 0 :(得分:0)
试试这个
$query=("INSERT INTO survey_question_responses (participant_id,question_id,answer_text,answer_option)
VALUES ('$participant_id','$question_id','$answer_text','$answer_option')");
答案 1 :(得分:0)
当您使id字段自动递增时,请不要通过INSERT查询插入它。
将查询写为
INSERT INTO survey_question_responses (participant_id, question_id, answer_text, answer_option)
VALUES ('$participant_id', '$question_id', '$answer_text', '$answer_option')
您还应该解释或发送表格的结构。