The method attribute of a form can have two values: GET and POST. The difference between GET and POST methods lies in how the information is transmitted to the PHP script.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<body>
<form action="script.php" method="get">
User: <input type="text" name="user" /><br />
<input type="radio" name="gen" value="man" />Man
<input type="radio" name="gen" value="woman" />Woman<br />
<input type="submit" value="Send" />
</form>
</body>
</html>
After the user fills the form and clicks the "submit" (Send) button, the URL sent to the server could look something like this:
<?php if (isset($_GET['user']) && isset($_GET['gen'])) { $user = $_GET['user']; $gen = $_GET['gen']; echo 'User: '. $user. ' - gender: '. $gen; } ?>
Before using data received through get (or post), is indicated to check if they were set /sent (using the "isset()" function).
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<body>
<a href="index.php?src=php&id=8" title="PHP">PHP Tutorial</a>
</body>
</html>
This link example has an URL with two keys in the query string (after the "?" character), one called src and the other called id. In the "index.php" file you can manipulate these values. All you have to do is reference the key within the $_GET.
<?php if (isset($_GET['src']) && isset($_GET['id'])) { // php instructions } else { // other php instructions } ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<body>
<form action="script.php" method="post">
Name: <input type="text" name="user" />
<input type="submit" value="Send" />
</form>
</body>
</html>
When the user clicks the "submit" (Send) button, script.php is called, the URL will look like this:
<?php if (isset($_POST['user'])) { echo 'Welcome '. $_POST['user']; } else { echo 'Welcome visitor'; } ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<body>
<form action="script.php?id=789" method="post">
Name: <input type="text" name="user" />
<input type="submit" value="Send" />
</form>
</body>
</html>
This code submits a form via the POST method, and when the form is posted, the code sends some values along the URL via the GET method ( "id=789", defined in the address from "action" attribute). The URL will look like this:
<?php if (isset($_REQUEST['id']) && isset($_REQUEST['user'])) { $id = $_REQUEST['id']; $user = $_REQUEST['user']; echo 'Welcome '. $user. ' - ID: '. $id; } else { echo 'Welcome visitor'; } ?>• If there are data received via GET and POST at the same time (through URL address and from a form), with the same "name" to both ($_GET['name'] and $_POST['name'), the $_REQUEST['name'] will contain the value of $_POST['name'].
<?php if(isset($_REQUEST['thename'])) echo $_REQUEST['thename']; // CoursesWeb.net ?> <form action="zz.php?thename=MarPlo" method="post"> <input type="text" name="thename" value="CoursesWeb.net" /> <input type="submit" value="Send" /> </form>
<input type="checkbox" name="a_name" value="value" checked="checked" />
#id { background:url("path_to_image.png"); background-size:contain; background-repeat:no-repeat; }
var rest8_7 = 8 % 7; alert(rest8_7);
$nr = ceil(3.5); echo $nr; // 4