HTML CODE对于页面
<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)
?>
答案 0 :(得分: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);
?>
答案 1 :(得分: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'];
....
答案 2 :(得分:0)
在表单中,您有form method =“post”,当您使用GET存储值时,更改表单方法=“GET”或使用
$_POST['survey_question_response_id'];
而不是
$_GET['survey_question_response_id'];
等其他变量也是如此。
你也错过了“;”这里“echo($ survey_id)”