0

我正在将数据从 iphone 应用程序插入到 mysql,但它没有将数据插入到表中我回显结果和输入的值,但它也没有显示任何值

页面的 HTML 代码

  <html>


  <head>
  <title>data to server</title>
  </head>
  <body>
  <form action="surveyAnswer.php" method="post" enctype="multipart/form-data"><br>

  <INPUT TYPE = "Text" VALUE ="1" NAME = "survey_question_response_id">

  <INPUT TYPE = "Text" VALUE ="1" NAME = "survey_id">
  <INPUT TYPE = "Text" VALUE ="1" NAME = "question_id">
  <INPUT TYPE = "Text" VALUE ="1" NAME = "survey_response_answer_id">
   <input type="submit" value="Upload File">
  </form>
  </body>
  </html>



     <?php
     $host = ""; 
     $user = ""; 
     $pass = ""; 
     $database = ""; 

     $linkID = mysql_connect($host, $user, $pass) or die("Could not connect to host."); 
     mysql_select_db($database, $linkID) or die("Could not find database."); 

     $survey_question_response_id=$_POST['survey_question_response_id'];
     $survey_id=$_POST['survey_id'];
     $question_id=$_POST['question_id'];
     $survey_response_answer_id=$_POST['survey_response_answer_id'];
     echo($survey_question_response_id);
     $query=("INSERT INTO survey_question_responses   (survey_question_response_id,survey_id,question_id,survey_response_answer_id)
     VALUES ('$survey_question_response_id', '$survey_id','$question_id','$survey_response_answer_id')");
     mysql_query($query,$con);
     printf("Records inserted: %d\n", mysql_affected_rows());
     echo($survey_id) 
    ?>
4

3 回答 3

1

您的form方法是POST并且您正在使用$_GET来捕获变量。使用$_POST代替$GET来解决您的问题。

此外,错误的标签语法。

<form action="surveyAnswer.php" method="post" enctype="multipart/form-data">

这指向surveyAnswer.php。因此,将下面的代码放入surveyAnswer.php页面中,并将其从显示 html 表单的页面中删除。

    <?php

       $survey_question_response_id=$_POST['survey_question_response_id'];
       $survey_id=$_POST['survey_id'];
       $question_id=$_POST['question_id'];
       $survey_response_answer_id=$_POST['survey_response_answer_id'];
       $query=("INSERT INTO survey_question_responses     (survey_question_response_id,survey_id,question_id,survey_response_answer_id)
      VALUES ('$survey_question_response_id', '$survey_id','$question_id','$survey_response_answer_id')");
     mysql_query($query,$con);
     printf("Records inserted: %d\n", mysql_affected_rows());
     echo($survey_id);

 ?>
于 2012-08-03T07:20:04.320 回答
0

您使用POST进行操作,但在您的 PHP 代码中使用 $_GET

更改所有 $_GET:

 <?php
   $survey_question_response_id=$_POST['survey_question_response_id'];
   // OR eighter to
   $survey_question_response_id=$_REQUEST['survey_question_response_id'];
   ....
于 2012-08-03T07:21:44.227 回答
0

在您的表单中,您有 form method="post" ,当您使用 GET 存储值时,可以更改您的表单 method="GET" 或使用

$_POST['survey_question_response_id'];  

代替

$_GET['survey_question_response_id'];

等其他变量也是如此。

你也缺少“;” 这里“回声($survey_id)”

于 2012-08-03T07:23:39.300 回答