wizzy886 Posted June 10, 2013 Share Posted June 10, 2013 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 = "£"; $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> Quote Link to comment https://forums.phpfreaks.com/topic/279007-php-form-with-if-statement/ Share on other sites More sharing options...
Irate Posted June 10, 2013 Share Posted June 10, 2013 Use $_POST['answer'] and set <form action="profit_calc.php" method="POST"> Quote Link to comment https://forums.phpfreaks.com/topic/279007-php-form-with-if-statement/#findComment-1435216 Share on other sites More sharing options...
Solution Barand Posted June 10, 2013 Solution Share Posted June 10, 2013 Couple of other errors $pnd = "£"; - there should be a ; after pound $_REQUEST['answer'] = $answer; should be $answer = $_REQUEST['answer']; Quote Link to comment https://forums.phpfreaks.com/topic/279007-php-form-with-if-statement/#findComment-1435221 Share on other sites More sharing options...
wizzy886 Posted June 11, 2013 Author Share Posted June 11, 2013 Thank you a lot. I believe it is working fully. Quote Link to comment https://forums.phpfreaks.com/topic/279007-php-form-with-if-statement/#findComment-1435388 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.