Forms
After entry and database connections, we want to build a web page that get some data from the user and insert it in the database. We can get the data, in two different ways:
- $_GET:
Open our example.php file in our editor. Clean all the codes in it. Just write:
<?php
echo “xxxx”;
?>
In our browser’s address bar, write the url:
http://localhost/example.php?id=1
and press Enter. What we see is the xxxx writing in browser.
If we change example.php like below:
<?php
$get_data = $_GET['id'];
echo $get_data;
?>
In the above requested url, the user gives us an id parameter as a data. In our php file, we get this data by using $_GET['id'];. After this change, we will see ‘1′ in screen. - $_POST:
If we want to post datas in a secret way, we’ ll use html forms. By this way, they can not be seen in the address bar. I will talk about why the secret way in the further lessons.
First of all, we will create a form, inside this form there will be a table.
<html>
<head>
</head>
<body>
<form name=”myfrm” action=”example.php” method=”POST”>
<table>
<tr>
<td>
<input type=”text” name=”FirstName” value=”">
</td>
</tr>
<tr>
<td>
<input type=”submit” name=”btn” value=”SAVE”>
</td>
</tr>
</table>
</form>
</body>
</html>
We have a table that has two rows. In the first row, there is an input tag for text fields. In the second row, we have a submit button name btn. <form> and </form> tags surrounded our table. This means with submit button we will post our data. The data that posts with the form goes to the program which was written in the action part of the form.
