1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Having Trouble With Maths Script

Discussion in 'BlackHat Lounge' started by scottlpool2003, Jul 9, 2009.

  1. scottlpool2003

    scottlpool2003 Newbie

    Joined:
    May 6, 2009
    Messages:
    14
    Likes Received:
    7
    Hey guys, I need to develop a website as part of my placement project for uni but I'm having a hard deal from the start.

    I need to develop a website that includes some example questions where users enter the sum and see the answer. I've done this bit with no problem.

    My problem is showing the sum and making the user answer the question and using an IF statement to calculate the answer and check it against what the user inputted. If they got it right I need to show "GOOD JOB" Else, "HARD LUCK"

    It's driving me insane, I'd appreciate it greatly if someone can help me out!

    PHP:
    <?
    if(
    $_POST['Submit']!=''){
    $variable_a $_POST['variable_a'];
    $variable_b $_POST['variable_b'];

    $result $variable_a $variable_b;
    echo 
    "<h1>$variable_a + $variable_b = $result</h1>";

    if 
    $txtans = ($variable_a $variable_b));
    echo
    "great job!";
    }
    ?>

    <form name="calc" method="post">
    <input name="variable_a" value="2" type="text" id="variable_a">
    +
    <input name="variable_b" value="1" type="text" id="variable_b">

    <input name="txtans" type="text" id="variable_b">
    <input type="submit" name="Submit" value="Calc">
    </form> 
     
  2. scottlpool2003

    scottlpool2003 Newbie

    Joined:
    May 6, 2009
    Messages:
    14
    Likes Received:
    7
    It's okay guys I managed to solve it myself, just tired I guess so excuse me for my sloppy example above hehe. Here is what I came up with:

    PHP:
    <?
    if(
    $_POST['Submit']!=''){
    $variable_a $_POST['variable_a'];
    $variable_b $_POST['variable_b'];
    $txtans $_POST['txtans'];

    $result $variable_a $variable_b;
    echo 
    "<h1>$variable_a + $variable_b = $result<br></h1>";
    echo 
    "Your answer was: $txtans<br>";
    if ( 
    $txtans == $result ) {
        echo 
    "<font color=green><b>CORRECT!</b></font>";
    } else {
        echo 
    "<font color=red><b>INCORRECT!</b></font>";
    }






    }


    ?>

    <form name="calc" method="post">
    <input name="variable_a" value="2" type="text" id="variable_a">
    +
    <input name="variable_b" value="1" type="text" id="variable_b">

    <input name="txtans" type="text" id="variable_b">
    <input type="submit" name="Submit" value="Calc">
    </form>