php - How to get echo to return equation? -
this question has answer here:
i trying create small form adds amounts html form code found below
html page-->
<html> <head> <meta charset="utf-8"> <meta name="viewport" content ="width=device-width,initial-scale=1,user scalable=yes" /> <title>nmaws form</title> <style type="text/css"> div#container { width: 800px; position: relative; margin-top: 0px; margin-left: auto; margin-right: auto; text-align: left; } </style> <style type="text/css"> body { text-align: center; margin: 0; background-color: #ffffff; color: #000000; } </style> </head> <body> <form method="post" attribute="post" action="calcsubmit.php"> <br> <b>name:<br> <input type="text" id="name" name="name"><br><br> email:<br> <input type="text" id="email" name="email"><br><br> cell number:<br> <input type="text" id="cell" name="cell"><br> <p>number of people in home:<br/> <select name="occupants" id="occupants" style="width:100px"><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option><option value="10">10</option></select></p> <p>how spend on<br>bottled water each week?<br/> <select name="water" id="water" style="width:100px"><option value="5">$0 $5</option><option value="10">$5 $10</option><option value="15">$10 $15</option><option value="20">$15 $20</option><option value="25">$20 $25</option></select></p> <p>how many loads of laundry<br>do each week?<br/> <select name="laundry" id="laundry" style="width:100px"><option value="1">1</option><option value="2">2</option><option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option><option value="10">10</option></select></p> <p></p> <button type="submit" name="answer" id="answer" value="answer" style="width:100px; height:100px;"><font size='4'>calculate savings</font></button> </form> </body> </html>
php page--->
<html> <head> <meta charset="utf-8"> <title>savings</title> </head> <body> <p>savings are: <?php if($_post["answer"]) { echo "$water + $laundry + $occupants"; } ?> </p> </body> </html>
the result + +, php isnt attempting equation not seeing wrong here
you haven't declared variables anywhere. you're looking $_post
ed variables.
if want return equation:
<?php if($_post["answer"]) { echo $_post['water'] . ' + ' . $_post['laundry'] . ' + ' . $_post['occupants']; } ?>
or if want return answer
<?php if($_post["answer"]) { echo $_post['water'] + $_post['laundry'] + $_post['occupants']; } ?>
Comments
Post a Comment