Problem with a script



Here it is:

<?php

if($_SERVER['REQUEST_METHOD']=='POST'){

$Number=$_POST['Number'];
$Email=$_POST['Email'];
$Number2=0;
$error=0;

$Variable1=$_POST['Variable1'];
$Variable2=$_POST['Variable2'];
$Variable3=$_POST['Variable3'];
$Variable4=$_POST['SVariable4'];
$Variable5=$_POST['Variable5'];
$Variable6=$_POST['Variable6'];
$Variable7=$_POST['IVariable7'];
$Variable8=$_POST['Variable8'];
$Check=$_POST['Check']; //We will use this to determine if we
should do data checks

if (empty($Variable1)){
$msg1=" * You have not answered this question.";
$error++;
}
if (empty($Variable2)){
$msg2=" * You have not answered this question.";
$error++;
}
if (empty($Variable3)){
$msg3=" * You have not answered this question.";
$error++;
}
if (empty($Variable4)){
$msg4=" * You have not answered this question.";
$error++;
}
if (empty($Variable5)){
$msg5=" * You have not answered this question.";
$error++;
}
if (empty($Variable6)){
$msg6=" * You have not answered this question.";
$error++;
}
if (empty($Variable7)){
$msg7=" * You have not answered this question.";
$error++;
}

$Variable9=$_POST['Variable9'];
$Variable10=$_POST['Variable10'];
$Variable11=$_POST['Variable11'];
$Variable12=$_POST['Variable12'];
$Variable13=$_POST['Variable13'];
$Variable14=$_POST['Variable14'];
$Variable15=$_POST['Variable15'];
$Variable16=$_POST['Variable16'];
$Variable17=$_POST['Variable17'];


for ($i=0; $i<$Number; $i++){
if (empty($Variable9[$i])){
$msg[i]=" * You have not answered this question.";
$error++;
}
if (empty($Variable10[$i])){
$msg[i]=" * You have not answered this question.";
$error++;
}
if (empty($Variable11[$i])){
$msg[i]=" * You have not answered this question.";
$error++;
}
if (empty($Variable12[$i])){
$msg[i]=" * You have not answered this question.";
$error++;
}
if (empty($Variable13[$i])){
$msg[i]=" * You have not answered this question.";
$error++;
}
if (empty($Variable14[$i])){
$msg[i]=" * You have not answered this question.";
$error++;
}
if (empty($Variable15[$i])){
$msg[i]=" * You have not answered this question.";
$error++;
}
if (empty($Variable16[$i])){
$msg[i]=" * You have not answered this question.";
$error++;
}
if (empty($Variable17[$i])){
$msg[i]=" * You have not answered this question.";
$error++;
}
} //closes FOR loop



if ($error>0){
echo "<form action=\"survey.php\" method=\"POST\">
<input type=\"hidden\" name=\"Email\" value=\"$Email\" />
<input name=\"Number\" type=\"hidden\" value=\" $Number\" />
<table width=\"700\" border=\"0\" cellpadding=\"0\" align=\"center
\">
<tr><td colspan=\"25\"><strong><center>PART 1 - SURVEY</center></
strong> <br/></td></tr>
<tr><td align=\"right\"></tr>
<tr><td align=\"right\"></td></tr>
<tr><td colspan=\"25\">Please answser the following questions:<br/
<br/></td> </tr>
<tr><td colspan=\"25\" bgcolor=\"#CCCCCC\">1. Question 1?</
td> </tr>
<tr>
<td align=\"center\"><input name=\"Variable1\" type=\"radio\" value=
\"Excellent\" /> Excellent</td>
<td align=\"center\"><input name=\"Variable1\" type=\"radio\" value=
\"Good\" /> Good</td>
<td align=\"center\"><input name=\"Variable1\" type=\"radio\" value=
\"Average\" /> Average</td>
<td align=\"center\"><input name=\"Variable1\" type=\"radio\" value=
\"Poor\" /> Poor</td>
<td colspan=\"21\">$msg1</td></tr>
<tr><td colspan=\"25\" bgcolor=\"#CCCCCC\">2. Question 2?</td></tr>
<tr>
<td align=\"center\"><input name=\"Variable2\" type=\"radio\" value=
\"Excellent\" /> Excellent</td>
<td align=\"center\"><input name=\"Variable2\" type=\"radio\" value=
\"Good\" /> Good</td>
<td align=\"center\"><input name=\"Variable2\" type=\"radio\" value=
\"Average\" /> Average</td>
<td align=\"center\"><input name=\"Variable2\" type=\"radio\" value=
\"Poor\" /> Poor</td>
<td colspan=\"21\">$msg2</td></tr>
<tr><td colspan=\"25\" bgcolor=\"#CCCCCC\">3. Question 3?</td></tr>
<tr>
<td align=\"center\"><input name=\"Variable3\" type=\"radio\" value=
\"Excellent\" /> Excellent</td>
<td align=\"center\"> <input name=\"Variable3\"type=\"radio\" value=
\"Good\" /> Good</td>
<td align=\"center\"><input name=\"Variable3\" type=\"radio\" value=
\"Average\" /> Average</td>
<td align=\"center\"><input name=\"Variable3\" type=\"radio\" value=
\"Poor\" /> Poor</td>
<td colspan=\"21\">$Variety</td>
</tr>
<tr><td colspan=\"25\" bgcolor=\"#CCCCCC\">4. Question 4?</td></
tr>
<tr>
<td align=\"center\"><input name=\"Variable4\" type=\"radio\" value=
\"Excellent\" /> Excellent</td>
<td align=\"center\"><input name=\"Variable4\" type=\"radio\" value=
\"Good\" /> Good</td>
<td align=\"center\"> <input name=\"Variable4\" type=\"radio\" value=
\"Average\" /> Average</td>
<td align=\"center\"><input name=\"Variable4\" type=\"radio\" value=
\"Poor\" /> Poor</td>
<td colspan=\"21\">$msg4</td>
</tr>
<tr><td colspan=\"25\" bgcolor=\"#CCCCCC\">5. Question 5?</td></tr>
<tr>
<td align=\"center\"><input name=\"Variable5\" type=\"radio\" value=
\"Excellent\" /> Excellent</td>
<td align=\"center\"><input name=\"Variable5\" type=\"radio\" value=
\"Good\" /> Good</td>
<td align=\"center\"><input name=\"Variable5\" type=\"radio\" value=
\"Average\" /> Average</td>
<td align=\"center\"> <input name=\"Variable5\" type=\"radio\" value=
\"Poor\" /> Poor</td>
<td colspan=\"21\"> $msg5</td>
</tr>
<tr>
<td colspan=\"25\" bgcolor=\"#CCCCCC\">6. Question 6?</td>
</tr>
<tr>
<td align=\"center\"><input name=\"Variable6\" type=\"radio\" value=
\"Excellent\" /> Excellent</td>
<td align=\"center\"> <input name=\"Variable6\" type=\"radio\" value=
\"Good\" /> Good</td>
<td align=\"center\"><input name=\"Variable6\" type=\"radio\" Value=
\"Average\"/> Average</td>
<td align=\"center\"><input name=\"Variable6\" type=\"radio\" value=
\"Poor\" /> Poor</td>
<td colspan=\"21\">$msg6</td>
</tr>
<tr>
<td colspan=\"25\" bgcolor=\"#CCCCCC\">7. Question 7?</td></tr>
<tr>
<td align=\"center\"><input name=\"Variable7\" type=\"radio\" value=
\"Excellent\" /> Excellent</td>
<td align=\"center\"><input name=\"Variable7\" type=\"radio\" value=
\"Good\" /> Good</td>
<td align=\"center\"><input name=\"Variable7\" type=\"radio\" value=
\"Average\" /> Average</td>
<td align=\"center\"> <input name=\"Variable7\" type=\"radio\" value=
\"Poor\" /> Poor</td>
<td colspan=\"21\">$msg7</td>
</tr>
</table>
<br/
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ADDITIONAL
COMMENTS: <br/><div align=\"center\"><textarea name=\"Variable8\" cols=
\"83\" rows=\"10\"></textarea></div><div align=\"center\"><br/>
<br/>
<strong>
<center>";

if ($Number>0){
echo "<table width=\"700\" border=\"0\" cellpadding=\"5\">
<tr><td colspan=\"10\"><strong><center>PART 2 - SURVEY
</center> </strong></td></tr><tr><td colspan=\"10\">&nbsp;</td></tr>
<tr><td colspan=\"10\"><div align=\"center\">Please fill out
each section below. </div></td></tr></table><br/></center></strong>";
$SeminarNumber=1;

while ($Number2<$Number){
echo "<table width=\"700\" border=\"0\" cellpadding=\"0\" align=
\"center\">
<tr><td colspan=\"60\" align=\"center\"><strong>Seminar
Number
$SeminarNumber</strong></td></tr>
<tr><td align=\"right\">Variable9: </td><td colspan=\"5\"><input
type=\"text\" name=\"Variable9[]$Number2\" value=\"\" width=\"250\"/
</td></td><td colspan=\"21\">
$msg[$Number]</td></tr>
<tr><td colspan=\"60\">&nbsp;</td></tr>
<tr><td colspan=\"60\" bgcolor=\"#CCCCCC\">1. Question 10?</td></
tr>
<tr>
<td align=\"center\"><input name=\"Variable10]$Number2\" type=
\"radio\" value=\"Excellent\" />Excellent</td>
<td align=\"center\" ><input name=\"Variable10[]$Number2\" type=
\"radio\" value=\"Good\" />Good</td>
<td align=\"center\" ><input name=\"Variable10[]$Number2\" type=
\"radio\" value=\"Average\" />Average</td>
<td align=\"center\" ><input name=\"Variable10[]$Number2\" type=
\"radio\" value=\"Poor\" />Poor</td><td colspan=\"21\">$msg[$Number]</
td>
</tr>
<tr><td colspan=\"60\" bgcolor=\"#CCCCCC\">2. Question 11?</td></
tr>
<tr>
<td align=\"center\"><input name=\"Variable11[]$Number2\" type=
\"radio\" value=\"Excellent\" />Excellent</td>
<td align=\"center\"><input name=\"Variable11[]$Number2\" type=
\"radio\" value=\"Good\" />Good</td>
<td align=\"center\"><input name=\"Variable11[]$Number2\" type=
\"radio\" value=\"Average\" />Average</td>
<td align=\"center\"><input name=\"Variable11[]$Number2\" type=
\"radio\" value=\"Poor\" />Poor</td><td colspan=\"21\"> $msg[$Number]
</td>
</tr>
<tr><td colspan=\"60\" bgcolor=\"#CCCCCC\">3. Question 12?</td></
tr>
<tr>
<td align=\"center\"><input name=\"Variable12[]$Number2\" type=
\"radio\" value=\"Excellent\" />Excellent</td>
<td align=\"center\"><input name=\"Encouraged[]$Number2\" type=
\"radio\" value=\"Good\" />Good</td>
<td align=\"center\"><input name=\"Variable12[]$Number2\" type=
\"radio\" value=\"Average\" />Average</td>
<td align=\"center\"><input name=\"Variable12[]$Number2\" type=
\"radio\" value=\"Poor\" />Poor</td><td colspan=\"21\">$msg[$Number]</
td></tr>
<tr><td colspan=\"60\" bgcolor=\"#CCCCCC\">4. Question 13
</td></tr>
<tr>
<td align=\"center\"><input name=\"Variable13[]$Number2\" type=
\"radio\" value=\"Excellent\" />Excellent</td>
<td align=\"center\"><input name=\"Variable13[]$Number2\" type=
\"radio\" value=\"Good\" />Good</td>
<td align=\"center\"><input name=\"Variable13[]$Number2\" type=
\"radio\" value=\"Average\" />Average</td>
<td align=\"center\"><input name=\"Variable13[]$Number2\" type=
\"radio\" value=\"Poor\" />Poor</td><td colspan=\"21\">$msg[$Number]</
td>
</tr>
<tr><td colspan=\"60\" bgcolor=\"#CCCCCC\"> 5.Question 14? </
td></tr>
<tr>
<td align=\"center\"><input name=\"Variable14[]$Number2\" type=
\"radio\" value=\"Excellent\" />Excellent</td>
<td align=\"center\"><input name=\"Variable14[]$Number2\" type=
\"radio\" value=\"Good\" />Good</td>
<td align=\"center\"><input name=\"Variable14[]$Number2\" type=
\"radio\" value=\"Average\" />Average</td>
<td align=\"center\"><input name=\"Variable14[]$Number2\" type=
\"radio\" value=\"Poor\" />Poor</td><td colspan=\"21\">$msg[$Number]</
td></tr>
<tr><td colspan=\"60\" bgcolor=\"#CCCCCC\">6.Question 15?. </td>
</tr>
<tr>
<td align=\"center\"><input name=\"Variable15[]$Number2\" type=
\"radio\" value=\"Excellent\" />Excellent</td>
<td align=\"center\"><input name=\"Variable15[]$Number2\" type=
\"radio\" value=\"Good\" />Good</td>
<td align=\"center\"><input name=\"Variable15[]$Number2\" type=
\"radio\" value=\"Average\"/>Average</td>
<td align=\"center\"><input name=\"Variable15[]$Number2\" type=
\"radio\" value=\"Poor\" />Poor</td><td colspan=\"21\">$msg[$Number]</
td></tr>
<tr><td colspan=\"60\"><hr/></td></tr>
</table><br/>";

$Number2++;
$SeminarNumber++;
} //Closes While Loop

echo "<table width=\"700\" border=\"0\" cellpadding=\"0\" align=
\"center\">
<tr><td colspan=\"60\" bgcolor=\"#CCCCCC\">Question 16: </td>
</tr>
<tr><td colspan=\"60\" align=\"center\"><div align=\"center
\"><textarea name=\"Variable16[]\" cols=\"83\" rows=\"5\"></textarea>
</div></td></tr>
<tr><td>&nbsp;<input type=\"hidden\" name=\"Check\" value=\"1\"</
td></tr>
<tr><td bgcolor=\"#CCCCCC\">ADDITIONAL COMMENTS: </td></tr>
<tr><td><div align=\"center\"><textarea name=\"Variable17[]\" cols=
\"83\" rows=\"10\"></textarea></div><br/></td></tr>
</table>
<div align=\"center\"><br/>If you are interested in receiving
information or materials, please email me at <a href=
\"mailto:email@xxxxxxxxx\";>email@xxxxxxxxx</a>.</div>
<div align=\"center\"><br/><input name=\"Submit\" type=\"Submit\"
value=\"Submit\">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input name=\"Reset\" type=
\"Reset\" value=\"Reset\"></div>
</form>";
} //closes the IF ($Number2>0) loop for if the user entered a
number for seminars

} //closes the IF ($error>0) loop
else{
include('submit.php');
}
} //closes the check POST validation IF


else{
echo"You can not access this page directly. To complete the survey,
go to
<br/><a href =\"http://www.website.com/index.php\";>Survey Form</a>";
}
?>

I tried formatting it for easy viewing, don't know if I succeeded. A
brief explanation is in order. The first page of the form asks a user
for a number and their email address. The number and email address are
passed to the second page of the form, which is the script listed
above. First thing we do is declare local variables. Next, we check
for any empty variables. If there are, $error>0 and we display the
form. If $error<=0, we call the submit.php page which writes
everything to the database.

The FOR loop in the middle determines if a customer entered a number
on the previous page. If there is a number, then it executes the next
block of code. If not, we skip this section. This way, if the customer
enters 0 or nothing for the number on the first page, then we don't
clutter up the screen with those questions. The WHILE loop right below
there, repeats certain questions for the number of times the user
entered on the first page. So there is a set of questions that is
asked once of all users, and a set of questions that is asked a number
of times, depending on what number the customer entered. The form
repeats the questions the correct number of times.

I am trying to accomplish some form of data verification. For the
first set of question, data verification works correctly, by not
allowing you to move further until every question is answered.
However, it automatically displays the error messages when the page
loads. I can't use an inline if($_SERVER['REQUEST_METHOD']=='POST')
{ echo $msg[i]; } method, since the form is always posted. Inside of
the WHILE loop, I can only get it to verify $Variable9. It doesn't
even check the other fields . Since the same question may be asked 10
times, I need to specify which occurrence of the question was not
answered. That is why I use the FOR loop.

If you know of a way to make the current code work, or if you have a
better idea of how to do this from top to bottom, please let me know.
I would like to also be able to carry over the user's selections, so
that they don't have to recheck each box, if they only left off one.

.



Relevant Pages

  • Re: RS-232 serial communication
    ... >The problem is that it repeats only every ~15ms. ... >there any way to speed up the frequency of the loop? ... >there some overhead that I can cut out by changing the code somehow? ... >Also the timing between the signals is not consistent. ...
    (comp.soft-sys.matlab)
  • Re: Vaguely on-topic: What crossover would you most want to see?
    ... The story is also set in what is essentially a time loop similar to ... cycle repeats. ... TARDIS' can't break out of a time loop. ...
    (rec.arts.drwho)
  • Re: Vaguely on-topic: What crossover would you most want to see?
    ... The story is also set in what is essentially a time loop similar to ... cycle repeats. ... TARDIS' can't break out of a time loop. ...
    (rec.arts.drwho)
  • Problem with Script
    ... } //Closes While Loop ... repeats the questions the correct number of times. ... I am trying to accomplish some form of data verification. ... If you know of a way to make the current code work, ...
    (comp.lang.php)
  • Re: Find method rebound sometimes
    ... Selection.HomeKey wdStory ' go to top ... Loop While ok = True ... In certain situations my code work fine, however inside tables or when I ... > Helmut Weber, MVP WordVBA ...
    (microsoft.public.word.vba.general)