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> 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"> Link to comment https://forums.phpfreaks.com/topic/279007-php-form-with-if-statement/#findComment-1435216 Share on other sites More sharing options...
Barand Posted June 10, 2013 Share Posted June 10, 2013 Couple of other errors $pnd = "£"; - there should be a ; after pound $_REQUEST['answer'] = $answer; should be $answer = $_REQUEST['answer']; 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. 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
Archived
This topic is now archived and is closed to further replies.