Вы находитесь на странице: 1из 23

GET & POST

3 Important Things Related to FORM

• Method
The form method determines how the form input data is sent
and processed. There are 2 types of methods: POST and GET

• Action
Action form determines the form input data processing file. If
this action is left blank (action = "") then the form input data
processing is done on the same page. So the form and processor
pages can be separated or put together

• Submit button
The button that functions as a triggers data transmission from
the form to the processor.
The ways to handle Form and Form
Action
• Combined between forms and form action
The input form and form action are carried out on the same page. This
way, the action attribute is emptied (action = "")

• Separated the form and form action


Form action is carried out on a separate page with the input form. If
using this method, the action attribute is filled with the name of the
form input data processing file
Example: (combined in a single file)
<html>
<head><title>Pengolahan form</title></head>
<body>
<form action=“” method=“post” name=“myform”>
Nama : <input type=“text” name=“nm” size=“25”>
<input type=“submit” value=“simpan” name=“spn”>
</form>
<?php
//pemroses data inputan form
If (isset($_POST[‘spn’])){
$nama=$_POST[‘nm’];
echo “Nama Anda : <b>$nama</b>”;}
?>
</body>
</html>
GET and POST

• To process dynamic programming, the value that will be processed is


needed, so there must be a role as the sender and recipient of that
value. The form will act as the sender and GET and POST will act as
recipients.
GET

• The captured data comes from the URL, so the data can be seen in
the URL
• The URL should have a length below 2000 characters
• As a limiting variable is &
• The GET method is used when the data is sent a little.
• This method uses $ _GET to process data.
• Data sent with this method will appear in the URL in the browser
address bar which is not safe for sensitive data (such as passwords).
GET

• For example, a search is made for the keyword ‘Belajar


PHP' on google, it will generate a url:
https://www.google.co.id/search?q=belajar+php&oq=belaj
ar+PHP&aqs=chrome.0.0l2j69i65j0l3.2706j0j7&sourceid=ch
rome&ie=UTF-8
Jika displit maka hasilnya akan menjadi seperti berikut :
• q=Belajar+PHP
• oq=Belajar+PHP
• aqs=chrome.0.0l2j69i65j0l3.2706j0j7
• sourceid=chrome
• ie=UTF-8
GET

• In the URL, when searching for 'Learn PHP', the browser will send 5
variables to Google. To capture the contents of this variable, Google
will capture the GET method.
GET

$q = $_GET['q'];
$oq = $_GET['oq'];
$aqs = $_GET['aqs'];
$sourceid = $_GET['sourceid'];
$ie = $_GET['ie'];
GET

• If open and click the submit button without entering a name and
address, then the Address Bar will form a ur:
: http://localhost/latihan/get.php?nama=&alamat=
• If entered: nama=John Doe dan alamat=Bandung, then the URL that
formed is:
http://localhost/latihan/get.php?nama=John+Doe&alamat=Bandung
Pay attention to the writing of the name above, every time there is a
space, it will be replaced with a plus sign (+) in the Addres Bar. The
question is, what if the added sign (+) is inserted, then the result will be
http://localhost/blog/get.php?nama=%2B&alamat=%2B.
Automatically the + sign is changed to% 2B, because the sign (+) in the
Address Bar is known as a space.
Contoh coding Method Get
<html>
<head><title>Pengolahan form</title></head>
<body>
<form action=“” method=“get” name=“myform”>
Nama : <input type=“text” name=“nama” size=“25”>
<input type=“submit” value=“simpan” name=“simpan”>
</form>

<?php
If (isset($_GET[‘simpan’]))
{
$nama=$_GET[‘nama’];
echo “Nama Anda : <b>$nama</b>”;
}
?>
</body>
</html>
John Doe

/Form01.php?nama=John+Doe&simpan=simpan

Disebut QUERY STRING


POST

• Receive sensitive data (e.g. email and password at login)


• There is no limit to the size of the file sent
• Capture array values
• Capture file values
• The POST method uses the $ _POST
• Able to store large amounts of data and file
• The data/file is stored in a separate place and does not depend on a
variable
POST & GET

 GET

POST 
Example: (Action file separated from Form
File form (form.html):

<html>
<head><title>Pengolahan form</title></head>
<body>
<form action=“simpan.php” method=“post” name=“myform”>
Nama Pelanggan : <input type=“text” name=“nama” size=“25”
placeholder=“Nama Pelanggan”><br/>
Alamat Pelanggan : <textarea name="alamat" placeholder="Alamat
Pelanggan" cols="23" rows="5"></textarea><br/>
<input type=“submit” value=“Simpan” name=“Simpan”>
</form>
</body>
</html>
Contoh coding FORM

Action file of form (simpan.php) :

<?php
If (isset($_POST[‘Simpan’]))
{
$nama=$_POST[‘nama’];
echo “Nama Anda : <b>$nama</b>”;
}
?>
PHP AND DATABASE
koneksi.php
simpan.php
Hasil simpan.php (action file)
tampil.php
Hasil tampil.php

Вам также может понравиться