Jump to content

PHP form with IF statement


wizzy886

Recommended Posts

I am currently trying to make a simple math sort of form where I can define two main variables that I then subtract to work out a theoretical profit. I may try and plug in a rand() into the income and costs but for now I kept it simple. I am struggling to make the final If statement work. It does not know that the variable is 5 9I have put a comment where I am referring to).

 

All help will be greatful, thanks.

 

profit_calc.php

<?php
	$pnd = "&pound";

	$income= 10;
	echo '<p>Income = ' .$pnd.$income. '</p>';

	$costs= 5;
	echo '<p>Costs = ' .$pnd.$costs. '</p>';

	$profits=$income-$costs;
	echo '<p>Profit = ' .$pnd.$profits. '</p>';


		if (!empty($_REQUEST['answer'])) {
			$_REQUEST['answer'] = $answer;

/* What Do I Do Here */
				if ($answer == $profits) {
					echo "Correct.";
				} else {
					echo "Incorrect.";
				}
		} else {
			$answer = NULL;
			echo "You did not enter anything.";
		}

?>

<form action="profit_calc.php">
	<p><input type="text" name="answer"></p>
		<p><input type="submit" name="submit" value="submit"></p>
</form>

Link to comment
https://forums.phpfreaks.com/topic/279007-php-form-with-if-statement/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.