在mysql数据库中插入数据不起作用

时间:2012-08-27 11:19:09

标签: php mysql

我使用以下代码在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

1 个答案:

答案 0 :(得分: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()  ); 
}

插入数据。