mgoblue4 Posted June 18, 2010 Share Posted June 18, 2010 Hello, I am fairly new to PHP to please be easy on me I am having trouble with a calculator form, currently it is not displaying the result after you click the submit button. http://stopsmokingecig.com/smoking-calc.php Here is the code.... <form action="<?=$_SERVER['PHP_SELF']?>" method="post"> <input type="text" name="packs" value="" />How many packs a week do you smoke?<br> <input type="text" name="price" value="" />How much do you pay per pack?<br> <input type="text" name="months" value="" />Over how many months?<br> <?php echo "$number"; ?> <input type="submit" name="multiply" value="Calculate" /> </form> <?php if (isset($_POST['multiply'])) { $a = $_POST['packs']; $b = $_POST['price']; $c = $_POST['months']; $number = $a * 4.3333333 * $c * $b; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/205216-calculator-form-help/ Share on other sites More sharing options...
jcbones Posted June 18, 2010 Share Posted June 18, 2010 Your echo is above your setting of the variable. <form action="<?=$_SERVER['PHP_SELF']?>" method="post"> <input type="text" name="packs" value="" />How many packs a week do you smoke?<br> <input type="text" name="price" value="" />How much do you pay per pack?<br> <input type="text" name="months" value="" />Over how many months?<br> <?php if (isset($_POST['multiply'])) { $a = $_POST['packs']; $b = $_POST['price']; $c = $_POST['months']; $number = $a * 4.3333333 * $c * $b; } echo "$number"; ?> <input type="submit" name="multiply" value="Calculate" /> </form> Quote Link to comment https://forums.phpfreaks.com/topic/205216-calculator-form-help/#findComment-1074182 Share on other sites More sharing options...
mgoblue4 Posted June 18, 2010 Author Share Posted June 18, 2010 WOW! What a dumb/obvious mistake! I'm embarrassed ha ha, thank you very much for your help. Quote Link to comment https://forums.phpfreaks.com/topic/205216-calculator-form-help/#findComment-1074184 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.