vampke Posted February 16, 2007 Share Posted February 16, 2007 Hi guys, First post here and totally newby on php. I tried to get this script to work but i can't. I need a user to answer some questions with a radio box, each radio box will have a specific number assigned to it. At the end, the sum of these is shown to the users. apparently the script will work 'somewhat'. If I answer all but one questions with option 5 and the other with option 4 i will get 25 as a result, where it should be 24. example on http://flor.astralwebhost.org/quiz.html php code: <?php $result = intval($_POST['question1']) + intval($_POST['question2']) + intval($_POST['question3']) + intval($_POST['question4']) + intval($_POST['question5']) ; if ($result < '21') { $msg="<p>score = " . $result . ". Not bad.</p> "; } elseif ($result ='25') { $msg="<p>Perfect score! " . $result . " points!</p> "; } elseif ($result >'20') { $msg="<p>Loser! Only " . $result . " points.</p>"; } ?> <?php print $msg; ?> html code: <form action="calc.php" method="post"> question1<br /> <input type="radio" name="question1" value="1">value=1<br /> <input type="radio" name="question1" value="2">value=2<br /> .... <input type="radio" name="question5" value="5">value=5<br /> <br /> <input name="post" type="submit" value="post" /> </form> anyone any ideas? Quote Link to comment Share on other sites More sharing options...
ScotDiddle Posted February 16, 2007 Share Posted February 16, 2007 vampke, Howdy! I ran your script through Zend Studio 5.5 Professional ( $299 from Zend.com ) and it pointed to the problem right away... Your line : elseif ($result ='25') { Should be: elseif ($result == '25') { which means: If $result is EXACTLY EQUAL To the Value '25', then do something. The way you have it coded, you are re-assigning the value from your $_POST arithmetic to '25' by your use of a single equal sign. Scot L. Diddle, Richmond VA Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted February 16, 2007 Share Posted February 16, 2007 your correct ScotDiddle although you dont need a program worth that much to spot an error like that. Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted February 16, 2007 Share Posted February 16, 2007 PMSL Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted February 16, 2007 Share Posted February 16, 2007 PMSL you've lost me on that... :S Quote Link to comment Share on other sites More sharing options...
ScotDiddle Posted February 16, 2007 Share Posted February 16, 2007 ProjectFear, The "worth" of a program product is relative. I know the syntax of PHP pretty well, but I did not spot the error manually. I popped out at me as I saw the value of $result change from 24 to 25 by using the IDE. As a noobee myself, I find the use of tools that are available go a great way towards productivity and an increased understanding of what PHP can, and cannot do, and why thing you thought would work, don't I agree that Zend Studio 5.5 Professional is expensive, but I have never regretted spending the money. Scot L. Diddle, Richmond VA Quote Link to comment Share on other sites More sharing options...
vampke Posted February 16, 2007 Author Share Posted February 16, 2007 great! thanks! still just learning this, so stupid errors will occur edit: btw why will it show 25 points out of 25? this line does not seem to be altering the sum ($result) does it? edit2: never mind, after rereading your reply i understand thanks! Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted February 16, 2007 Share Posted February 16, 2007 yes, i suppose if you have the money to spend. i dont have that kinda money to spend. i just use my good old notepad. Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted February 16, 2007 Share Posted February 16, 2007 PMSL you've lost me on that... :S Pee eye ess ess MySelf Laughing... Quote Link to comment 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.