Php mysql数据库中的数据插入不工作

Php mysql数据库中的数据插入不工作,php,mysql,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['re

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

回答id、参与者id、问题id、答案选项、答案文本

(回答id、参与者id、问题id、答案选项)

您的行“$participant\u id=$\u POST['participant\u id'] 缺少分号(;)

也请使用

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

插入数据。

如果有问题,请检查错误。例如,使用
echo mysql_error()
。是的,它会在/home/content/i/h/u/ihus235/html/cs/emrapp/SyncSurveyTest.php中在线给出类似解析错误的错误:语法错误、意外的T_变量16@Vprimachenko我在评论中给出了错误,请检查this@UmerSumra
$\u POST['participant\u id'后缺少分号
同时查看
PDO
谢谢它工作正常,但respone id是整数格式,我认为它存储了0个值如何解决此问题所有其他工作都很好不要在值中添加“$response\u id”周围的“$response\u id”(“$response\u id”[…]行。然后在mysql中将其解析为整数。当变量本身为空时,这没有帮助。在插入数据之前,您需要验证这一点(使用if(!isset($variable)))