...

View Full Version : Simple add numbers



Jon W
12-16-2008, 09:28 PM
<?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

Jon W
12-16-2008, 09:39 PM
<?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.

Jon W
12-16-2008, 09:57 PM
I've figure it out. Nevermind.


Thanks anyways guys.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum