-3
我想要做的是運行一個選擇語句爲每個答案選擇數據庫中的答案,其中questionID = $i
和userID = $userID
所以我有這樣的查詢設置到目前爲止,但不知道我的'失蹤或我是否正確,沒有失去任何東西?另外無論我做什麼兩個字段都有值,但我仍然收到我需要填寫兩個表單域的錯誤消息。表格處理
<?php
$i = 1;
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
?>
<dl>
<dt style="width: 190px;"><label for="answer[<?php echo $row['id']; ?>]"><?php echo $row['question'] ?></label></dt>
<dd><input type="text" name="answer<?php echo $i ?>[<?php echo $row['id']; ?>]" size="54" /></dd>
</dl>
<?php
++$i;
}
?>
if (empty($_POST['answer1'][$i]) || trim($_POST['answer1'][$i])=="") {$errors = "yes";}
if (empty($_POST['answer2'][$i]) || trim($_POST['answer2'][$i])=="") {$errors = "yes";}
// Error checking, make sure all form fields have input
if ($errors == "yes") {
// Not all fields were entered error
$message = "You must enter values to all of the form fields!";
$output = array('errorsExist' => true, 'message' => $message);
} else {
$userID = mysqli_real_escape_string($dbc,$_POST['userID']);
$answer1 = mysqli_real_escape_string($dbc,$_POST['answer1'][$i]);
$answer2 = mysqli_real_escape_string($dbc,$_POST['answer2'][$i]);
$query = "SELECT * FROM manager_users_secretAnswers WHERE questionID = '".$questionID."' AND userID = '".$userID."'";
$result = mysqli_query($dbc,$query);
echo $query;
哥們_ $ {ID} ..你一直在重複同樣的即使我們告訴你要這樣做,也是錯誤的。空(修剪($ _ POST ['answer1'] [$ i]))就足夠了,你不必做額外的||事情。 – FinalForm
PEAR :: QuickForm – powtac