-5

我正在使用以下代码在 mysql 数据库中插入数据

<?php

   $con = mysql_connect("surveyipad.db.6420177.hostedresource.com","test","test");
  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'];

 echo($response_id);

   $query=("INSERT INTO survey_question_responses 

  (response_id,participant_id,question_id,answer_option)
   VALUES ('$response_id', '$participant_id','$question_id','$answer_option')");

   mysql_query($query,$con);
  printf("Records inserted: %d\n", mysql_affected_rows());
  echo($response_id)
  ?>

我在mysql中的表就像

response_id,participant_id,question_id,answer_option_answer_text

4

1 回答 1

0

response_id,participant_id,question_id,answer_option_answer_text vs

(response_id、participant_id、question_id、answer_option)

并且您的行“ $participant_id=$_POST['participant_id'] ”缺少分号(;)

也请使用

if( !mysql_query( $query, $con ) ) { 
echo("Failure: " . mysql_error()  ); 
}

插入数据。

于 2012-08-27T11:24:12.680 回答