{"id":413,"date":"2021-12-02T08:22:57","date_gmt":"2021-12-02T08:22:57","guid":{"rendered":"http:\/\/tietokanta.dy.fi:8243\/mikko\/wordpress\/?p=413"},"modified":"2021-12-02T11:10:15","modified_gmt":"2021-12-02T11:10:15","slug":"the-_post-array","status":"publish","type":"post","link":"http:\/\/tietokanta.dy.fi:8243\/mikko\/wordpress\/index.php\/2021\/12\/02\/the-_post-array\/","title":{"rendered":"The $_POST Array"},"content":{"rendered":"\n<p>The POST request is usually preferred (because it avoids placing unsightly data in the browser\u2019s address bar), and so we use it here. The<br>web server bundles up all of the user input (even if the form was filled out with a hundred fields) and puts in into an array named $_POST.<\/p>\n\n\n\n<p>Depending on whether a form has been set to use the POST or the GET method, either the $_POST or the $_GET associative array will be populated with the form data. They can both be read in exactly the same way.<\/p>\n\n\n\n<p>Each field has an element in the array named after that field. So, if a form contains a field named isbn, the $_POST array contains an element keyed by the word isbn. The PHP program can read that field by referring to either $_POST[&#8216;isbn&#8217;] or $_POST[&#8220;isbn&#8221;] (single and double quotes have the same effect in this case).<\/p>\n\n\n\n<p>There is no reason to write to an element in the $_POST array. Its<br>only purpose is to communicate information from the browser to<br>the program, and you\u2019re better off copying data to your own variables before altering it.<\/p>\n\n\n\n<p>So, back to the get_post function, which passes each item it retrieves through the real_escape_string method of the connection object to escape any quotes that a hacker may have inserted in order to break into or alter your database, like this:<\/p>\n\n\n\n<p><strong>function get_post($conn, $var)<br>{<br>return $conn-&gt;real_escape_string($_POST[$var]);<br>}<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The POST request is usually preferred (because it avoids placing unsightly data in the browser\u2019s address bar), and so we use it here. Theweb server bundles up all of the user input (even if the form was filled out with a hundred fields) and puts in into an array named $_POST. Depending on whether a &hellip; <a href=\"http:\/\/tietokanta.dy.fi:8243\/mikko\/wordpress\/index.php\/2021\/12\/02\/the-_post-array\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">The $_POST Array<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"http:\/\/tietokanta.dy.fi:8243\/mikko\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/413"}],"collection":[{"href":"http:\/\/tietokanta.dy.fi:8243\/mikko\/wordpress\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/tietokanta.dy.fi:8243\/mikko\/wordpress\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/tietokanta.dy.fi:8243\/mikko\/wordpress\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/tietokanta.dy.fi:8243\/mikko\/wordpress\/index.php\/wp-json\/wp\/v2\/comments?post=413"}],"version-history":[{"count":2,"href":"http:\/\/tietokanta.dy.fi:8243\/mikko\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/413\/revisions"}],"predecessor-version":[{"id":455,"href":"http:\/\/tietokanta.dy.fi:8243\/mikko\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/413\/revisions\/455"}],"wp:attachment":[{"href":"http:\/\/tietokanta.dy.fi:8243\/mikko\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=413"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/tietokanta.dy.fi:8243\/mikko\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=413"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/tietokanta.dy.fi:8243\/mikko\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=413"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}