我无法将文本框中输入的数据插入MYSQL数据库。我试图将来自多个文本框的输入插入到数据库中。
<?php
include('questionDB.php');
if(isset($_POST['submit'])){
$questionID = $_POST['id'];
$answer = mysql_real_escape_string(htmlspecialchars($_POST['answer']));
mysql_query("INSERT INTO answers(question_id, answer_body) VALUES ($questionID, $answer)");
}
?>
<form name="auctionQuestion" method="post">
<?php
$auctionSurvey = "SELECT question_id, survey_id, question_body FROM questions
WHERE survey_id='1'";
$aucResult = mysql_query($auctionSurvey) or die (mysql_error());
while($auctionRow = mysql_fetch_assoc($aucResult)){
echo $auctionRow['question_body']. "<input type=\"text\" name=\"answer\"><BR>";
?>
<input type="hidden" name="id" value="<?php echo $auctionRow['question_id'] ?>">
<?php
}
?>
<input type="submit" name="submit" value="Submit">
</form>
答案 0 :(得分:1)
要做的第一件事就是生成正确的HTML,以便获得变量数组。 我认为这将是这样的
echo $auctionRow['question_body'] . "<input type=\"text\" name=\"answer[]\"><BR>";
与其他领域类似。
然后,当你收到帖子时,使用print_r($ _ POST)来查看你的确切内容。从那里开始
答案 1 :(得分:1)
使用:
VALUES ('$questionID', '$answer')
或:
VALUES ('" . $questionID . "', '" . $answer . "')
而不是VALUES ($questionID, $answer)