Presentation is loading. Please wait.

Presentation is loading. Please wait.

Dr. John P. Abraham Professor UTRGV eCommerce CSCI 6314

Similar presentations


Presentation on theme: "Dr. John P. Abraham Professor UTRGV eCommerce CSCI 6314"— Presentation transcript:

1 Dr. John P. Abraham Professor UTRGV eCommerce CSCI 6314
PHP Forms Dr. John P. Abraham Professor UTRGV eCommerce CSCI 6314

2 Begin with HTML <html> <head> </head> <body> <?php ?> <form> </form> </body> </html>

3 Now add form under html <form action = "<?php $_PHP_SELF ?>" method = "POST"> Your Name Please: <input type = "text" name = "name" /> <br/>Your Age Please : <input type = "text" name = "age" /> <br/> Address : <input type = " " name =" "/> <br/><input type = "submit" />

4 Discuss first line of the form
<form action = "<?php $_PHP_SELF ?>" method = "POST"> The form tag requires two attributes: action and method. Action says to where the results will be sent to. You can include an url here or what I did, which will produce the current address. The results are stored in an Array with the name of $_POST[]; each element will have an identifier specified in the code. Method is either get or post. POST is used to send data to a server to create/update a resource. Get caches multiple get requests.

5 The GET method produces a long string that appears in your server logs, in the browser's Location: box. The GET method is restricted to send upto 1024 characters only. Never use GET method if you have password or other sensitive information to be sent to the server. GET can't be used to send binary data, like images or word documents, to the server. The data sent by GET method can be accessed using QUERY_STRING environment variable. The PHP provides $_GET associative array to access all the sent information using GET method. The POST method transfers information via HTTP headers. The information is encoded as described in case of GET method and put into a header called QUERY_STRING. The POST method does not have any restriction on data size to be sent. The POST method can be used to send ASCII as well as binary data. The data sent by POST method goes through HTTP header so security depends on HTTP protocol. By using Secure HTTP you can make sure that your information is secure. The PHP provides $_POST associative array to access all the sent information using POST method.

6 Second line of the form Reading objects
Your Name Please: <input type = "text" name = "name" /> The input tag and the attribute text will create a textBox for us. The name is the most important, that will become the identifier in the #_POST[name] array. There are different types we can use, text, submit, reset, textarea, , etc.

7 Retrieving data submitted
Recall that the global array $_POST[] contains all data that was submitted. We can retrieve each data element by its name, for example $POST[age]; Let’s echo just one element: echo $_POST['name']; <?php echo $_POST['name']; ?>

8 Complete code <html> <head> </head> <body> <form action = "<?php $_PHP_SELF ?>" method = "POST"> Your Name Plase: <input type = "text" name = "name" /> <br/>Your Age Please : <input type = "text" name = "age" /> <br/> Address : <input type = " " name =" "/> <br/><input type = "submit" /> <?php //if (isset($_POST['submit])) { echo "<br/> <h1>You Entered: <br/></h1>"; echo ($_POST['name'] ); echo "<br/>"; echo $_POST['age']; echo $_POST[' ']; ?></form> </body> </html>

9


Download ppt "Dr. John P. Abraham Professor UTRGV eCommerce CSCI 6314"

Similar presentations


Ads by Google