Reading Data in a form: using text fields, lesson -2-…
taring lesson 2 from this tutorial, I will talk about text fields. I will show you how to send data using a text field of a form and then reading data in that form again using PHP. So let’s begin…
Step *1: open xammp, open your browser and open the editor. In htdocs folder which is usually in (C:\xampp\htdocs). in this folder create another folder and name it (textfield). Inside this folder you will save the files we will create in this lesson. In this folder we will have two files textfield.html and phptextfield.php.
Step *2: using the editor, create an HTML file, name it textfield.html, type this code in it and save.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>entering data into text field</title> </head> <body> <h1> entering data into text field </h1> <form method="post" action="phptextfield.php"> what's your name? <input name="data" type="text" /> <input type="submit" value="send" /> </form> </body> </html>
All the work will be done using forms and how to pass data from forms to web pages. In forms you need to specify the data with which your data will be sent: either “get” or “post”. The difference between them is ” get” will used to send data insecure, you could understand me if you take a look on the URL in the address bar or your browser when you use “get”, you could see the information you entered in the input boxes appear in the URL, usually the data separates from the file name by a question mark and spaces replaced with + sign. but “post” is used to send data in a secure way, if you look at the URL in your browser then you will see nothing of your information appears there. This way we told the browser how to send data, just like this:
<form method="get"> or <form method="post">
Now we should tell the browser where to send the data?
So we will use the action attribute to assign the URL. Just like this
<form method="get" action="www.phpexample.com/phptextfield.php>
This form element will send its data to this link (phpexample.com/phpreader.php) when we click on submit button. if the phptextfield.php file is located inside the same directory of textfield.html, then the link could be written like this:
<form method="get" action="phptextfield.php>
If there is no action attribute, the data in the form will be sent back to the exact same script when the user clicks the submit button.
<br />
To start handling text fields, we should ask for the user’s name. give it a name using the name attribute and set the value attribute to “text”, just like this.
<input name="data" type="text" />
The other important thing in forms is the submit button. We can name the submit button anything we like, by assigning the desired name in the value attribute.
<input type="submit" value="send">
Also we can use reset button, it uses for reset data in all the HTML controls in the forum, to their default values.
<input type="reset" value="reset">
Step *3: using the editor, create a PHP file, name it phptextfield.php, type this code in it and save.
<html> <head> </head> <body> <h1> thank you for answearing </h1> <?php echo $_REQUEST["data"]; ?> </body> </html>
The $_REQUEST array holds the data from both $_GET and $_POST, therefore I used echo to print theses information that $_REQUEST array holds. In this example it holds the user name.
Now this is all about how we could read data in a form using PHP. Seeyaz next week.
<br />








I feel that is one of the so much important info for me. And i’m satisfied reading your article. But should observation on some normal things, The web site taste is great, the articles is actually nice : D. Good process, cheers
Just wish to say your article is as astounding. The clarity on your post is simply cool and that i can suppose you are an expert in this subject. Fine together with your permission allow me to take hold of your feed to keep up to date with forthcoming post. Thanks 1,000,000 and please keep up the gratifying work.
Thanks a lot for sharing this with all folks you really understand what you are speaking about! Bookmarked. Kindly also visit my site =). We can have a link trade arrangement among us
Very great post. I just stumbled upon your blog and wanted to say that I’ve truly enjoyed surfing around your blog posts. After all I will be subscribing in your feed and I hope you write once more very soon!