Jump to content

PHP form with IF statement


wizzy886
Go to solution Solved by Barand,

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.