berry05 Posted May 7, 2009 Share Posted May 7, 2009 i tried searching phpfreaks and i found a thread that was kind of what i needed but not quite...anyways... I'm trying to make a code so that when someone clicks a generate button a random math problem shows up. a polynomial math problem. I know i have to type the polynomial math problem in my code but how do i make it so that when someone clicks generate problem a problem shows up? Link to comment https://forums.phpfreaks.com/topic/157175-random-math-problem/ Share on other sites More sharing options...
Maq Posted May 7, 2009 Share Posted May 7, 2009 How are the problems stored? Link to comment https://forums.phpfreaks.com/topic/157175-random-math-problem/#findComment-828195 Share on other sites More sharing options...
berry05 Posted May 7, 2009 Author Share Posted May 7, 2009 here's a script i have for baby math... but now I want someone to click a button and it generates the problem.. I have the problem stored in HTML <style type="text/css"> <!-- .style3 {font-size: 18px} --> </style> <form id="form1" name="form1" method="post" action=""> <span class="style3">1+1 = </span><strong> <label> </label> </strong> <label> <input type="text" name="textfield" id="textfield" /> </label> <label> <input type="submit" name="Go" id="Go" value="Go" /> </label> <?php session_start(); $question1 = (isset($_POST['textfield'])) ? $_POST['textfield'] : FALSE; $answer = "Correct!!"; if($question1 == "2"){ $_SESSION['answer'] = "Correct!!!" ; } elseif($question1 == ""){ echo ""; } elseif($question1 < "2"){ echo "To low of a number!"; }else { echo "To high of a number!"; } echo $_SESSION['answer']; ?> </form> <form id="form2" name="form1" method="post" action=""> <span class="style3">2+2 = </span><strong> <label> </label> </strong> <label> <input type="text" name="textfield2" id="textfield2" /> </label> <label> <input type="submit" name="Go2" id="Go2" value="Go" /> </label> <?php session_start(); $question2 = (isset($_POST['textfield2'])) ? $_POST['textfield2'] : FALSE; $answer1 = "Correct!!"; if($question2 == "4"){ $_SESSION['answer1'] = "Correct!!!" ; } elseif($question2 == ""){ echo ""; } elseif($question2 < "4"){ echo "To low of a number!"; }else { echo "To high of a number!"; } echo $_SESSION['answer1']; ?> </form> <form id="form3" name="form1" method="post" action=""> <span class="style3">3+3 = </span><strong> <label> </label> </strong> <label> <input type="text" name="textfield3" id="textfield3" /> </label> <label> <input type="submit" name="Go3" id="Go3" value="Go" /> </label> <?php session_start(); $question3 = (isset($_POST['textfield3'])) ? $_POST['textfield3'] : FALSE; if($question3 == "6"){ $_SESSION['answer2'] = "Correct!!!" ; } elseif($question3 == ""){ echo ""; } elseif($question3 < "6"){ echo "To low of a number!"; }else { echo "To high of a number!"; } echo $_SESSION['answer2']; ?> </form> <form action="" method="post" name="form4" id="form4"> <strong> Clear? (Yes) (Do it twice)</strong> <label> <input type="text" name="textfield4" id="textfield4" /> </label> <label> <input type="submit" name="button" id="button" value="Clear" /> </label> <?php $clear = (isset($_POST['textfield4'])) ? $_POST['textfield4'] : FALSE; if($clear == "yes"){ session_destroy(); } elseif($clear == "Yes"){ session_destroy(); } ?> </form> <p> Link to comment https://forums.phpfreaks.com/topic/157175-random-math-problem/#findComment-828196 Share on other sites More sharing options...
Ken2k7 Posted May 7, 2009 Share Posted May 7, 2009 If you're setting the $question# vars to either be the value or false, why does your else if statement doesn't check for if it's false? And do you need $_SESSION for this? Link to comment https://forums.phpfreaks.com/topic/157175-random-math-problem/#findComment-828250 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.