{"id":340,"date":"2010-07-30T01:05:30","date_gmt":"2010-07-30T05:05:30","guid":{"rendered":"http:\/\/www.searchenginegenie.com\/programming-blog\/?p=340"},"modified":"2015-07-29T01:32:44","modified_gmt":"2015-07-29T05:32:44","slug":"calculate-addsubmul-using-php","status":"publish","type":"post","link":"https:\/\/www.searchenginegenie.com\/programming-blog\/calculate-addsubmul-using-php\/","title":{"rendered":"Calculate add,sub,mul using php"},"content":{"rendered":"<p><strong>Steps:<\/strong><\/p>\n<p><strong>1. Create new html file and copy calculate.html code and save it as calculate.html.<\/strong><\/p>\n<p><strong>2. Create new php file and copy calculation.php code and save it as calculation.php.<\/strong><\/p>\n<p><strong>3. Run calculate.html, then it will display the html data.<\/strong><\/p>\n<p><strong>4. Enter value1, value2 and press add or sub or mul button and press calculate button.<\/strong><\/p>\n<p><strong>5. Then it will transfer to calculation.php which displays the output.<\/strong><\/p>\n<p><strong>calculate.htm:<\/strong><\/p>\n<p>[php]<\/p>\n<p>&lt;!DOCTYPE html PUBLIC &#8220;-\/\/W3C\/\/DTD XHTML 1.0 Transitional\/\/EN&#8221; &#8220;http:\/\/www.w3.org\/TR\/xhtml1\/DTD\/xhtml1-transitional.dtd&#8221;&gt;<br \/>\n&lt;html xmlns=&#8221;http:\/\/www.w3.org\/1999\/xhtml&#8221;&gt;<br \/>\n&lt;head&gt;<br \/>\n&lt;meta http-equiv=&#8221;Content-Type&#8221; content=&#8221;text\/html; charset=iso-8859-1&#8243; \/&gt;<br \/>\n&lt;title&gt;calculation&lt;\/title&gt;<br \/>\n&lt;\/head&gt;<\/p>\n<p>&lt;body&gt;<br \/>\n&lt;form method=&#8221;post&#8221; action=&#8221;calculation.php&#8221;&gt;<br \/>\nValue 1: &lt;input type=&#8221;text&#8221; name=&#8221;val1&#8243; size=&#8221;7&#8243;&gt;&lt;br \/&gt;&lt;br \/&gt;<br \/>\nValue 2: &lt;input type=&#8221;text&#8221; name=&#8221;val2&#8243; size=&#8221;7&#8243;&gt;<br \/>\n&lt;p&gt;<br \/>\n&lt;input type=&#8221;radio&#8221; name=&#8221;calculate&#8221; value=&#8221;add&#8221;\u00a0 \/&gt;<br \/>\nadd<br \/>\n&lt;input type=&#8221;radio&#8221; name=&#8221;calculate&#8221; value=&#8221;sub&#8221;\u00a0 \/&gt;<br \/>\nsub<br \/>\n&lt;input type=&#8221;radio&#8221; name=&#8221;calculate&#8221;\u00a0 value=&#8221;mul&#8221;\/&gt;<br \/>\nmul<br \/>\n&lt;\/p&gt;<br \/>\n&lt;input type=&#8221;submit&#8221; name=&#8221;submit&#8221; value=&#8221;calculate&#8221;\/&gt;<br \/>\n&lt;\/form&gt;<br \/>\n&lt;\/body&gt;<br \/>\n&lt;\/html&gt;<\/p>\n<p>[\/php]<\/p>\n<p>It displays the output as:<br \/>\nValue 1: <input name=\"val1\" size=\"7\" type=\"text\" \/>Value 2: <input name=\"val2\" size=\"7\" type=\"text\" \/><br \/>\n<input name=\"calculate\" type=\"radio\" value=\"add\" \/>add<br \/>\n<input name=\"calculate\" type=\"radio\" value=\"sub\" \/>sub<br \/>\n<input name=\"calculate\" type=\"radio\" value=\"mul\" \/>mul<br \/>\n<input name=\"submit\" type=\"submit\" value=\"calculate\" \/><\/p>\n<form action=\"calculation.php\" method=\"post\"><strong>calculation.php:<\/strong><\/form>\n<form action=\"calculation.php\" method=\"post\">[php]<br \/>\n&lt;\/form&gt;&lt;form action=&#8221;calculation.php&#8221; method=&#8221;post&#8221;&gt;&lt;!DOCTYPE html PUBLIC &#8220;-\/\/W3C\/\/DTD XHTML 1.0 Transitional\/\/EN&#8221; &#8220;http:\/\/www.w3.org\/TR\/xhtml1\/DTD\/xhtml1-transitional.dtd&#8221;&gt;<br \/>\n&lt;html xmlns=&#8221;http:\/\/www.w3.org\/1999\/xhtml&#8221;&gt;<br \/>\n&lt;head&gt;<br \/>\n&lt;meta http-equiv=&#8221;Content-Type&#8221; content=&#8221;text\/html; charset=iso-8859-1&#8243; \/&gt;<br \/>\n&lt;title&gt;Untitled Document&lt;\/title&gt;<br \/>\n&lt;\/head&gt;&lt;body&gt;<br \/>\n&lt;?php<br \/>\nif(($_POST[&#8216;val1&#8217;]==&#8221;&#8221;) || ($_POST[&#8216;val2&#8217;]==&#8221;&#8221;))<br \/>\n{<br \/>\nheader(&#8220;location: calculate.html&#8221;);<br \/>\nexit();<br \/>\n}<br \/>\nif($_POST[&#8216;calculate&#8217;]==&#8221;add&#8221;)<br \/>\n{<br \/>\n$result=$_POST[&#8216;val1&#8217;]+$_POST[&#8216;val2&#8217;];<br \/>\n}<br \/>\nelse if($_POST[&#8216;calculate&#8217;]==&#8221;sub&#8221;)<br \/>\n{<br \/>\n$result=$_POST[&#8216;val1&#8217;]-$_POST[&#8216;val2&#8217;];<br \/>\n}<br \/>\nelse if($_POST[&#8216;calculate&#8217;]==&#8221;mul&#8221;)<br \/>\n{<br \/>\n$result=$_POST[&#8216;val1&#8217;]*$_POST[&#8216;val2&#8217;];<br \/>\n}<br \/>\necho &#8220;Calculation is: $result&#8221;;<br \/>\n?&gt;<br \/>\n&lt;\/body&gt;<br \/>\n&lt;\/html&gt;&lt;\/form&gt;&lt;form action=&#8221;calculation.php&#8221; method=&#8221;post&#8221;&gt;<br \/>\n[\/php]<\/form>\n<form action=\"calculation.php\" method=\"post\">An example output for add by giving the input as value1 as 5 and value2 as 5 is:<\/form>\n<form action=\"calculation.php\" method=\"post\">Calculation is: 10<\/form>\n<form action=\"calculation.php\" method=\"post\"><\/form>\n","protected":false},"excerpt":{"rendered":"<p>Steps: 1. Create new html file and copy calculate.html code and save it as calculate.html. 2. Create new php file and copy calculation.php code and save it as calculation.php. 3. Run calculate.html, then it will display the html data. 4. Enter value1, value2 and press add or sub or mul button and press calculate button. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[15],"class_list":["post-340","post","type-post","status-publish","format-standard","hentry","category-php","tag-php-code"],"_links":{"self":[{"href":"https:\/\/www.searchenginegenie.com\/programming-blog\/wp-json\/wp\/v2\/posts\/340","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.searchenginegenie.com\/programming-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.searchenginegenie.com\/programming-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.searchenginegenie.com\/programming-blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.searchenginegenie.com\/programming-blog\/wp-json\/wp\/v2\/comments?post=340"}],"version-history":[{"count":13,"href":"https:\/\/www.searchenginegenie.com\/programming-blog\/wp-json\/wp\/v2\/posts\/340\/revisions"}],"predecessor-version":[{"id":792,"href":"https:\/\/www.searchenginegenie.com\/programming-blog\/wp-json\/wp\/v2\/posts\/340\/revisions\/792"}],"wp:attachment":[{"href":"https:\/\/www.searchenginegenie.com\/programming-blog\/wp-json\/wp\/v2\/media?parent=340"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.searchenginegenie.com\/programming-blog\/wp-json\/wp\/v2\/categories?post=340"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.searchenginegenie.com\/programming-blog\/wp-json\/wp\/v2\/tags?post=340"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}