I only want one submit button. As such, I understand the submit button must be outside the loop.
Each loop creates an "answer" and I want those answers to be included in the database so I can echo them on the page that is accessed by submit.
I'm lost. Any of your veteran coders help me walk through this one?
Or suggest a better way to take a list of questions from a database, allow the user to answer a particular section of them and show the results on submit.
Is there a way to assign a DIFFERENT variable to the "answer" based on each pass? Are the 'answers' stored in an array automatically on each pass? I am still learning and appreciate the help....
BTW, this is the output http://www.robertbartz.com/survey/01Sur.php which is great. I just need to be able to put the answers in a database...
Code: Select all
function getQuestions($dbc) {
$survID = $_SESSION["surveyid"];
$ansSizS = $_SESSION["answerSize"];
$query = 'SELECT * from survey_questions WHERE survey_id = ' . $survID . '';
$result = mysql_query($query);
$qNum = 1;
if ($result) {
while ($row = mysql_fetch_array($result, MYSQLI_ASSOC)) {
/* ################################ */
/* #### Define Post Variables ##### */
/* ################################ */
$body = $row['question_body'];
$ansSiz = $row['answer_length'];
if ($ansSiz==0) {
echo '
<div class="entry">
<span class="qTitle">'. $qNum . '. ' . $body.'</span><br/>
<form action="/survey/functions/sandbox2.php" method="post">
<input type="text" name="answer' . $qNum . '" size="' . $ansSizS . '" /><br/>
</div>';
} else {
echo '
<div class="entry">
<span class="qTitle">'. $qNum . '. ' . $body.'</span><br/>
<form action="/survey/functions/sandbox2.php" method="post">
<input type="text" name="answer' . $qNum . '" size="' . $ansSiz . '" /><br/>
<input type="hidden" name="questionid" value="' . $qNum . '" />
</div>';
}
} //END if
} //END while
echo '<div class="enrty"><input type = "submit" value="submit" />
</form>
</div>';