bassplaya4string Posted October 10, 2006 Share Posted October 10, 2006 I am trying to make a simple little survey that calculates the total score and if a field is left empty, it will return to the survey. All is well except the while statement near the end. I cant get it to return to the form if a question is not answered. can someone please take a look at it and help me out. I know this may seem elementary to some but I am only starting to use php alot. Thanks![code]<?php$questions = array($_POST["Q_1"], $_POST["Q_2"], $_POST["Q_3"], $_POST["Q_4"], $_POST["Q_5"], $_POST["Q_6"], $_POST["Q_7"], $_POST["Q_8"], $_POST["Q_9"], $_POST["Q_10"],);if (!isset($_POST['submit'])) { // if page is not submitted to itself echo the form?><html><head><title>Test</title></head><body><form method="post" action="<?php echo $PHP_SELF;?>">1. True leaders are born, not made.<br /> True:<input type="radio" value="1" name="Q_1"><br />False:<input type="radio" value="0" name="Q_1"><br /><br />2. If I take on a leadership role, I’ll improve my popularity.<br /> True:<input type="radio" value="1" name="Q_2"><br />False:<input type="radio" value="0" name="Q_2"><br /><br />3. The very best leaders know the value of keeping a low profile.<br /> True:<input type="radio" value="1" name="Q_3"><br />False:<input type="radio" value="0" name="Q_3"><br /><br />4. If you usually get along well with those in charge, you will probably be a good leader.<br /> True:<input type="radio" value="1" name="Q_4"><br />False:<input type="radio" value="0" name="Q_4"><br /><br />5. The best leaders always know what to do. <br /> True:<input type="radio" value="1" name="Q_5"><br />False:<input type="radio" value="0" name="Q_5"><br /><br />6. An effective leader must try to maintain a forceful personality.<br /> True:<input type="radio" value="1" name="Q_6"><br />False:<input type="radio" value="0" name="Q_6"><br /><br />7. My physical appearance has little or nothing to do with my becoming a leader.<br /> True:<input type="radio" value="1" name="Q_7"><br />False:<input type="radio" value="0" name="Q_7"><br /><br />8. I prefer reading fiction to nonfiction.<br /> True:<input type="radio" value="1" name="Q_8"><br />False:<input type="radio" value="0" name="Q_8"><br /><br />9. I usually stick to my decision even when it is unpopular with my group.<br /> True:<input type="radio" value="1" name="Q_9"><br />False:<input type="radio" value="0" name="Q_9"><br /><br />10. Being a quick decision-maker is an important trait of a good leader. <br /> True:<input type="radio" value="1" name="Q_10"><br />False:<input type="radio" value="0" name="Q_10"><br /><br /><input type="submit" value="submit" name="submit"></form><?} else {$i = 0while ($i < 10){$questions[$i] != null;$i++;}$score = $Q_1 + $Q_2 + $Q_3 + $Q_4 + $Q_5 + $Q_6 + $Q_7 + $Q_8 + $Q_9 + $Q_10;echo "Your score is ".$score.".<br />";}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/23498-help-with-simple-survey/ Share on other sites More sharing options...
tomfmason Posted October 10, 2006 Share Posted October 10, 2006 try placeing an echo and then wrapping the html in a single quote. Like this.[code]<?php$questions = array($_POST["Q_1"], $_POST["Q_2"], $_POST["Q_3"], $_POST["Q_4"], $_POST["Q_5"], $_POST["Q_6"], $_POST["Q_7"], $_POST["Q_8"], $_POST["Q_9"], $_POST["Q_10"],);if (!isset($_POST['submit'])) { // if page is not submitted to itself echo the form echo '<html><head><title>Test</title></head><body><form method="post" action="' . $PHP_SELF . '">1. True leaders are born, not made.<br /> True:<input type="radio" value="1" name="Q_1"><br />False:<input type="radio" value="0" name="Q_1"><br /><br />2. If I take on a leadership role, I’ll improve my popularity.<br /> True:<input type="radio" value="1" name="Q_2"><br />False:<input type="radio" value="0" name="Q_2"><br /><br />3. The very best leaders know the value of keeping a low profile.<br /> True:<input type="radio" value="1" name="Q_3"><br />False:<input type="radio" value="0" name="Q_3"><br /><br />4. If you usually get along well with those in charge, you will probably be a good leader.<br /> True:<input type="radio" value="1" name="Q_4"><br />False:<input type="radio" value="0" name="Q_4"><br /><br />5. The best leaders always know what to do. <br /> True:<input type="radio" value="1" name="Q_5"><br />False:<input type="radio" value="0" name="Q_5"><br /><br />6. An effective leader must try to maintain a forceful personality.<br /> True:<input type="radio" value="1" name="Q_6"><br />False:<input type="radio" value="0" name="Q_6"><br /><br />7. My physical appearance has little or nothing to do with my becoming a leader.<br /> True:<input type="radio" value="1" name="Q_7"><br />False:<input type="radio" value="0" name="Q_7"><br /><br />8. I prefer reading fiction to nonfiction.<br /> True:<input type="radio" value="1" name="Q_8"><br />False:<input type="radio" value="0" name="Q_8"><br /><br />9. I usually stick to my decision even when it is unpopular with my group.<br /> True:<input type="radio" value="1" name="Q_9"><br />False:<input type="radio" value="0" name="Q_9"><br /><br />10. Being a quick decision-maker is an important trait of a good leader. <br /> True:<input type="radio" value="1" name="Q_10"><br />False:<input type="radio" value="0" name="Q_10"><br /><br /><input type="submit" value="submit" name="submit"></form>';} else {$i = 0while ($i < 10){$questions[$i] != null;$i++;}$score = $Q_1 + $Q_2 + $Q_3 + $Q_4 + $Q_5 + $Q_6 + $Q_7 + $Q_8 + $Q_9 + $Q_10;echo "Your score is ".$score.".<br />";}?>[/code]Hope that helps,Tom Quote Link to comment https://forums.phpfreaks.com/topic/23498-help-with-simple-survey/#findComment-106634 Share on other sites More sharing options...
bassplaya4string Posted October 10, 2006 Author Share Posted October 10, 2006 I tried that and it can back with the same error as before: Parse error: parse error, unexpected T_WHILE in /home/content/H/a/l/HaloWeb/html/test.php on line 59.I think something is wrong with the while loop. Like I said before I am fairly new to php, so please be patient. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/23498-help-with-simple-survey/#findComment-106638 Share on other sites More sharing options...
php_coder_dvo Posted October 10, 2006 Share Posted October 10, 2006 why you dont use javascript for validating.. Quote Link to comment https://forums.phpfreaks.com/topic/23498-help-with-simple-survey/#findComment-106646 Share on other sites More sharing options...
HuggieBear Posted October 10, 2006 Share Posted October 10, 2006 You have no semicolon after [code=php:0]$i = 0[/code] in your while loop.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/23498-help-with-simple-survey/#findComment-106702 Share on other sites More sharing options...
whitehat Posted October 11, 2006 Share Posted October 11, 2006 To be hornest i cant help you with your own codeHowever if you see this (i'm a fan of this guy's scripts)[url=http://www.dhtmlgoodies.com/scripts/ajax-poller/ajax-poller.html]Poll script[/url] Quote Link to comment https://forums.phpfreaks.com/topic/23498-help-with-simple-survey/#findComment-107621 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.