Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jan 2008
    Posts
    334
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Simple add numbers

    PHP Code:
    <?php

    if($_GET['stop'] == true) {
        
        
    session_destroy(); 
    }


    if(isset(
    $_POST['check']) && $_POST['answer']) {

    session_start();

     if(
    $_SESSION['num'] =='') {
         
        
    session_start();
        
        
    $_SESSION['num'] == 2;
        
        }else {
            
            
    session_destroy();
            
        }    
     
      
    $problem $_SESSION['num'] + 2;
     
      if(
    $problem != $answer) {
          
          
    $wrong "Oops, try again";
          
          }else {
             
             
    session_start();
             
             
    $_SESSION['num'] = $answer;
             
              
          }  
          
          }




    ?>
        <?php echo $wrong?>
        
        <?php echo "$num + 2";  ?>
        
        <form action="<?php echo $_SERVER['PHP_SELF']; ?>"  method="post">
        <input name="answer" type="text" /><br /><br />
        <input name="check" type="submit" value="Check" />
        </form>
        
        
        <?php echo "Problem: $problem"?>
    I'm simply trying to make a form that will display a plus answer that everytime it will go up by two. So for example, 2 + 2 if you get that one right then 4 + 2 if you get that one right, 6 + 2 and so on. I seems to be doing something wrong. If I could get any help on this then that would be great.

    Jon W

  • #2
    Regular Coder
    Join Date
    Jan 2008
    Posts
    334
    Thanks
    9
    Thanked 0 Times in 0 Posts
    PHP Code:


    <?php

    if(isset($_POST['check']) && $_POST['answer'] !='') {
        
      
    session_start();
      
      if(
    $_SESSION['num'] =='') {
          
        
    $_SESSION['num'] = 2;
          
      }
      
        
    $problem $_SESSION['num'] + 2;
        
        if(
    $problem != $answer) {
        
            
    $wrong "You got the problem wrong";
        
            }else {
                
                
    session_start();
                
                
    $_SESSION['num'] = $answer;
                
            }
        
        
    }

    ?>
        <?php echo $wrong?>
        
        <?php echo "$num + 2";  ?>
        
        <form action="<?php echo $_SERVER['PHP_SELF']; ?>"  method="post">
        <input name="answer" type="text" /><br /><br />
        <input name="check" type="submit" value="Check" />
        </form>
        
        
        <?php echo "Problem: $problem"?>
    This one seems to be working better. But its not right just yet.
    Last edited by Jon W; 12-16-2008 at 09:42 PM.

  • #3
    Regular Coder
    Join Date
    Jan 2008
    Posts
    334
    Thanks
    9
    Thanked 0 Times in 0 Posts
    I've figure it out. Nevermind.


    Thanks anyways guys.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •