2012-08-03 72 views
0

我正在插入来自iphone应用数据到MySQL,但它不将数据插入表 我回声结果和inputed值,但它也没有显示出任何值将数据插入不工作

HTML代码MySQL数据库

<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) 
    ?> 

回答

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); 

?> 
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']; 
    .... 
+0

没有同样的事情再次无法正常工作 – user1567956 2012-08-03 07:26:36

+0

请更换的mysql_query($查询,$ CON);到mysql_query($ query,$ con)或die(mysql_error());并给我们的输出 – donald123 2012-08-03 07:29:47

+0

,你告诉我已经更新了代码,但它显示了回报[] – user1567956 2012-08-03 07:39:07

0

在你的表格你有形式方法=“post”在你存储数值时使用GET或者改变你的表单方法=“GET”或者使用

$_POST['survey_question_response_id']; 

代替

$_GET['survey_question_response_id']; 

等其他变量也是如此。

而且你缺少 “;”这里的 “回声($ survey_id)”

+0

我已经做过这样的,但它返回[] – user1567956 2012-08-03 07:42:08