1 / 30

Form & PHP

Form & PHP. Introduction. All of the following examples in this section will require two web pages. The first page retrieves information posted by the user, and the second sends the information from the web server and scripting engine back to the browser.

norah
Download Presentation

Form & PHP

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Form & PHP

  2. Introduction • All of the following examples in this section will require two web pages. • The first page retrieves information posted by the user, and the second sends the information from the web server and scripting engine back to the browser. • The first web page doesn’t have to contain any PHP script at all. • Second page contains PHP codes embedded in HTML codes.

  3. Getting Data from Form • An HTML form is a section of a document containing normal content, markup, special elements called controls (text field, checkboxes, radio buttons, drop down menu, text area), and labels on those controls. • Users generally "complete" a form by modifying its controls (entering text, selecting menu items, etc.), before submitting the form to an agent for processing (e.g., to a Web server, to a mail server, etc.)

  4. Getting Data from Form • To create a form using a pure HTML web page: Opening and closing <form> tags. (< form >……< /form> ) •  Any controls such as text field , radio button etc that are placed between the <form> tags, automatically become part of the form that is sent to the web server.

  5. Getting Data from Form • Method action tells the server which page to go to once the user has checked a submit button on the form • Example: <form method= post action =“test.php”> ……………. </form>

  6. Getting Data from Form • Attribute method controls the way that information is sent to the server • There are two values for attribute method: get and post • Example: <form method= post action = “test.php”> or <form method= get action =“test.php”> • In this course, most of our examples use post.

  7. Getting Data from Form Text Fields (text boxes) • Text fields are created using <input> element • Setting type attribute to text

  8. Getting Data from Form textfield.html  <html> <head></head> <body> <form method = post action = “textfield.php”> Enter your name here : <input name = “name” type=“text”> <br><br> <input type = submit > </form></body></html> textfield.php <html> <head></head> <body> My name is : <?php echo $name ; ?> </html>

  9. Getting Data from Form textfield.html textfield.php My name is hani

  10. Getting Data from Form Text area • use < textarea> tag instead of <input> tags because <textarea> allow us to set the size and number of rows and columns of the control.

  11. Getting Data from Form textarea.html  <html> <head></head> <body> <form method=post action="textarea.php"> <p>what are your favourite html editor? <textarea name="editor" rows="5" cols="50" > ultra edit visul interdev note pad crimson editor </textarea> <br> <br> <input type="submit"> </p></form></body></html>

  12. Getting Data from Form textarea.php  <html> <head></head> <body> My favourite HTML editor are: <? php echo $editor ; ?> </body> </html>

  13. Getting Data from Form textarea.html textarea.php My favourite HTML editor are :Ultra Edit Visual Interdev Note Pad Crimson Editor

  14. Getting Data from Form Checkboxes • Checkbox is counted as an individual entity. • Users can have several checkboxes ticked altogether, or none checked at all. • Checkboxes are created using <input> tag, setting type attribute to checkbox. • Each checkbox controls was named and set independently.

  15. Getting Data from Form checkboxes.html <html><head></head> <body> <form method=post action “checkboxes.php”> have you ever use sybase before? <input name="checkbox1" type="checkbox" value=“Sybase"> <br>Have you ever use oracle before? <input name="checkbox2" type="checkbox" value=“Oracle"> <br>Have you ever use sql server before? <input name="checkbox3" type="checkbox" value=“SQLServer"> <br><br> <input type="submit" > </form> </body> </html>

  16. Getting Data from Form checkboxes.php <html> <head></head> <body> <?php echo “$checkbox1<br>”; echo “$checkbox2<br>”; echo “$checkbox3<br>”; ?> </body> </html>

  17. Getting Data from Form checkboxes.html checkboxes.php Oracle SQLServer

  18. Getting Data from Form Radio buttons • Only one of the options / answers can be selected at a time. • Radio buttons are created using <input> tag , setting type attribute to radio. • Each radio buttons has a same name.

  19. Getting Data from Form radiobutton.html <html><head></head><body> <form method=post action="radiobutton.php"> c language,object oriented(java) .....can be considered as: <br><br> <input type="radio" name="radiobutton" value=“Networking"> networking <br> <input type="radio" name="radiobutton" value=“Programming Language" checked> programming language <br> <input type="radio" name="radiobutton" value=“Operating System"> operating system <br><input type=submit ></form></body></html>

  20. Getting Data from Form radiobutton.php <html> <head></head> <body> <? php echo “you selected the answer :$radiobutton”; ?> </body> </html>

  21. Getting Data from Form radiobutton.html radiobutton.php You selected the answer : Programming Language

  22. Getting Data from Form Dropdown List boxes • Dropdown list boxes are created using <select> and <option> tags. • The <select> tag that creates the list box encloses a number of <option> tags. the <option> tags each contain the text that corresponds to an item on the dropdown list.

  23. Getting Data from Form listboxes.html <html><head></head><body> <form method=post action="listbox.php"> what price of laptop are you looking to buy ? <br> <br> <select name="price"> <option selected>RM 3000- RM 3500</option> <option>RM 3500-RM 4000</option> <option>RM 4000-RM 4500</option> </select> <br><br> <input type=submit> </form></body></html>

  24. Getting Data from Form listbox.php <html> <head></head> <body> <?php echo “Price Range : $price" ; ?> </body> </html>

  25. Getting Data from Form listboxes.html listbox.php Price Range: RM 3000- RM 3500

  26. Inserting Data from Form Into Database • The next topic shows how to insert data from form into MySQL database. • The form has all type of form controls and the complete codes are shown in form_complete.html. • form_complete.html contains all HTML tags. • form_dbase.php contains PHP codes that send the data from form into MySQL database.

  27. Inserting Data from Form Into Database form_complete.html

  28. Inserting Data from Form Into Database form_dbase.php

  29. Inserting Data from Form Into Database form_complete.html

  30. Inserting Data from Form Into Database Database Table Database content

More Related