{"id":232,"date":"2009-07-27T22:57:54","date_gmt":"2009-07-27T21:57:54","guid":{"rendered":"http:\/\/www.codingfriends.com\/?p=232"},"modified":"2009-07-27T22:58:18","modified_gmt":"2009-07-27T21:58:18","slug":"add-two-numbers-4","status":"publish","type":"post","link":"https:\/\/www.codingfriends.com\/index.php\/2009\/07\/27\/add-two-numbers-4\/","title":{"rendered":"Add two numbers"},"content":{"rendered":"<p>This tutorial will add up two values that have been entered within the web page, I am going to use the web page functional aspects rather than the command line interface because php is mainly used within websites.<\/p>\n<p>The web page itself is using a form tag, this form tag allows for the web page to post data back to the server, where the php will use the posts ($_POST) array ( [<name of input>]).<\/p>\n<p>The source code is <\/p>\n<pre lang=\"javascript\">\r\n<?php\r\n       $value1 = $_POST['value1'];\r\n       $value2 = $_POST['value2'];\r\n?>\r\n<html>\r\n       <title>PHP - Add two numbers<\/title>\r\n       <body>\r\n              <form action=\"addtwonumbers.php\" method=\"post\">\r\n                     <input type=\"text\" name=\"value1\" value=\"0\" \/>\r\n                     <input type=\"text\" name=\"value2\" value=\"0\" \/>\r\n                     <input type=\"submit\" value=\"Calculate values\"\/>\r\n              <\/form>\r\n              Answer : <?php echo ($value1 + $value2); ?>\r\n       <\/body>\r\n<\/html>\r\n<\/pre>\n<p>if you save that as addtwonumbers.php within the php website configured directory and then open up that page via a web browser (e.g. http:\/\/localhost\/addtwonumbers.php, localhost means the local pc, just like 127.0.0.1 is the local ring e.g the pc itself to talk to itself via an IP). <\/p>\n<p>Just for completeness, this is the command line interface code.<\/p>\n<pre lang=\"javascript\">\r\n<?php\r\n echo \"Please enter value 1 : \";\r\n fscanf(STDIN, \"%d\\n\", $value1); \/\/ reads number from STDIN standard input\r\n echo \"Please enter value 2 : \";\r\n fscanf(STDIN, \"%d\\n\", $value2);\r\n echo \"Answer : \" .($value1 + $value2) . \"\\n\";\r\n?>\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial will add up two values that have been entered within the web page, I am going to use the web page functional aspects rather than the command line interface because php is mainly used within websites. The web page itself is using a form tag, this form tag allows for the web page &hellip; <a href=\"https:\/\/www.codingfriends.com\/index.php\/2009\/07\/27\/add-two-numbers-4\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Add two numbers<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[18,19,398,403,400],"class_list":["post-232","post","type-post","status-publish","format-standard","hentry","category-php","tag-apache","tag-iis","tag-linux","tag-php","tag-windows"],"_links":{"self":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/232","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/comments?post=232"}],"version-history":[{"count":2,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/232\/revisions"}],"predecessor-version":[{"id":234,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/232\/revisions\/234"}],"wp:attachment":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/media?parent=232"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/categories?post=232"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/tags?post=232"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}