I'm currently trying to creat a page that allows users to complete questions online. If they click submit without answering some of the questions the page is reloaded saying "You didn't answer question 1" etc. Now while I have this working fine, I can't retain their old selections! Ie: they get the error message and have to start again with a blank questionnaire. I'm not sure how to correct this. I've attached the important part of the code I'm currently working with. Note that this example only shows 2 questions, this is just to avoid repetition. In reallity there are a lot more questions and would like this functionality to exist in all cases. So any help would be much appreciated!
if (hasSurveyBeenCompleted ($connection, $user_id))
{
header("location: surveyCompleted.php");
}
//this branch is only triggered once submit has been pressed and the page "re runs" itself.
if (isset($_POST['submit']))
{
if (!isset($_POST["questionOne"])){
echo "you didn't fill question 1 out!";
} else if (!isset($_POST["questionTwo"])){
echo "you didn't fill question 2 out!";
} else {
$questionOne = $_POST["questionOne"];
$query = "INSERT into sms.new_survey (answerid, user_id , question_one) Values ($council_id, $user_id, $questionOne);";
pg_exec($connection, $query);
// All is good - write info to database and go to main surveys page
header("location: options.php");
}
}
?><html>
<head>
<title>User Info</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href="global.css" type="text/css">
</head>
<body class="bg" style="margin:20px;">
<form action="<? echo $_SERVER['PHP_SELF']; ?>" name="userinfoform" method="POST">
<h2><p>Please enter the appropriate responses and then click on the submit button:</p></h2>
<span style="color:#FF0000"></span>
<table width="603" border="0">
<tr>
<td colspan = 9>1. Are company x complying with your original and ongoing brief?</td>
</tr>
<tr>
<td><input type="radio" name="questionOne" value="1">1<span style="color:#FF0000"></span> </td>
<td><input type="radio" name="questionOne" value="2">2<span style="color:#FF0000"></span> </td>
<td><input type="radio" name="questionOne" value="3">3<span style="color:#FF0000"></span> </td>
<td><input type="radio" name="questionOne" value="4">4<span style="color:#FF0000"></span> </td>
<td><input type="radio" name="questionOne" value="5">5<span style="color:#FF0000"></span> </td>
<td><input type="radio" name="questionOne" value="6">6<span style="color:#FF0000"></span> </td>
<td><input type="radio" name="questionOne" value="7">7<span style="color:#FF0000"></span> </td>
<td><input type="radio" name="questionOne" value="8">8<span style="color:#FF0000"></span> </td>
<td><input type="radio" name="questionOne" value="9">9<span style="color:#FF0000"></span> </td>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<td colspan = 9>2. Are company X meeting their deadlines on time?</td>
</tr>
<tr>
<td><input type="radio" name="questionTwo" value="1">1<span style="color:#FF0000"></span> </td>
<td><input type="radio" name="questionTwo" value="2">2<span style="color:#FF0000"></span> </td>
<td><input type="radio" name="questionTwo" value="3">3<span style="color:#FF0000"></span> </td>
<td><input type="radio" name="questionTwo" value="4">4<span style="color:#FF0000"></span> </td>
<td><input type="radio" name="questionTwo" value="5">5<span style="color:#FF0000"></span> </td>
<td><input type="radio" name="questionTwo" value="6">6<span style="color:#FF0000"></span> </td>
<td><input type="radio" name="questionTwo" value="7">7<span style="color:#FF0000"></span> </td>
<td><input type="radio" name="questionTwo" value="8">8<span style="color:#FF0000"></span> </td>
<td><input type="radio" name="questionTwo" value="9">9<span style="color:#FF0000"></span> </td>
</tr>
<tr>
<td colspan = 9><input name="submit" type="submit" value="Submit"></td>
</tr>
</table>
</form>
</body>
</html>
so to reitterate - If the user doesn't click button 2, he gets a page returned to him saying "you didn't answer question 2" (that part works so far) and question one retains his original selection......(this doesn't work yet and this is where i need the help!)
Thanks!

New Topic/Question
Reply




MultiQuote




|