CHAPTER 7 Form & PHP. Introduction All of the following examples in this section will require two...
-
Upload
shannon-warren -
Category
Documents
-
view
217 -
download
3
Transcript of CHAPTER 7 Form & PHP. Introduction All of the following examples in this section will require two...
![Page 1: CHAPTER 7 Form & PHP. Introduction All of the following examples in this section will require two web pages. The first page retrieves information posted.](https://reader030.fdocuments.us/reader030/viewer/2022032415/56649f055503460f94c19b08/html5/thumbnails/1.jpg)
CHAPTER 7Form & PHP
![Page 2: CHAPTER 7 Form & PHP. Introduction All of the following examples in this section will require two web pages. The first page retrieves information posted.](https://reader030.fdocuments.us/reader030/viewer/2022032415/56649f055503460f94c19b08/html5/thumbnails/2.jpg)
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.
![Page 3: CHAPTER 7 Form & PHP. Introduction All of the following examples in this section will require two web pages. The first page retrieves information posted.](https://reader030.fdocuments.us/reader030/viewer/2022032415/56649f055503460f94c19b08/html5/thumbnails/3.jpg)
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.)
![Page 4: CHAPTER 7 Form & PHP. Introduction All of the following examples in this section will require two web pages. The first page retrieves information posted.](https://reader030.fdocuments.us/reader030/viewer/2022032415/56649f055503460f94c19b08/html5/thumbnails/4.jpg)
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.
![Page 5: CHAPTER 7 Form & PHP. Introduction All of the following examples in this section will require two web pages. The first page retrieves information posted.](https://reader030.fdocuments.us/reader030/viewer/2022032415/56649f055503460f94c19b08/html5/thumbnails/5.jpg)
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>
![Page 6: CHAPTER 7 Form & PHP. Introduction All of the following examples in this section will require two web pages. The first page retrieves information posted.](https://reader030.fdocuments.us/reader030/viewer/2022032415/56649f055503460f94c19b08/html5/thumbnails/6.jpg)
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.
![Page 7: CHAPTER 7 Form & PHP. Introduction All of the following examples in this section will require two web pages. The first page retrieves information posted.](https://reader030.fdocuments.us/reader030/viewer/2022032415/56649f055503460f94c19b08/html5/thumbnails/7.jpg)
Getting Data from Form
Text Fields (text boxes)• Text fields are created using <input> element• Setting type attribute to text
![Page 8: CHAPTER 7 Form & PHP. Introduction All of the following examples in this section will require two web pages. The first page retrieves information posted.](https://reader030.fdocuments.us/reader030/viewer/2022032415/56649f055503460f94c19b08/html5/thumbnails/8.jpg)
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>
![Page 9: CHAPTER 7 Form & PHP. Introduction All of the following examples in this section will require two web pages. The first page retrieves information posted.](https://reader030.fdocuments.us/reader030/viewer/2022032415/56649f055503460f94c19b08/html5/thumbnails/9.jpg)
Getting Data from Form
textfield.html
textfield.php
My name is hani
![Page 10: CHAPTER 7 Form & PHP. Introduction All of the following examples in this section will require two web pages. The first page retrieves information posted.](https://reader030.fdocuments.us/reader030/viewer/2022032415/56649f055503460f94c19b08/html5/thumbnails/10.jpg)
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.
![Page 11: CHAPTER 7 Form & PHP. Introduction All of the following examples in this section will require two web pages. The first page retrieves information posted.](https://reader030.fdocuments.us/reader030/viewer/2022032415/56649f055503460f94c19b08/html5/thumbnails/11.jpg)
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 editvisul interdevnote padcrimson editor</textarea><br><br><input type="submit"></p></form></body></html>
![Page 12: CHAPTER 7 Form & PHP. Introduction All of the following examples in this section will require two web pages. The first page retrieves information posted.](https://reader030.fdocuments.us/reader030/viewer/2022032415/56649f055503460f94c19b08/html5/thumbnails/12.jpg)
Getting Data from Form
textarea.php <html><head></head><body>My favourite HTML editor are: <? php echo $editor ; ?></body></html>
![Page 13: CHAPTER 7 Form & PHP. Introduction All of the following examples in this section will require two web pages. The first page retrieves information posted.](https://reader030.fdocuments.us/reader030/viewer/2022032415/56649f055503460f94c19b08/html5/thumbnails/13.jpg)
Getting Data from Form
textarea.html
textarea.php
My favourite HTML editor are :Ultra Edit Visual Interdev
Note Pad Crimson Editor
![Page 14: CHAPTER 7 Form & PHP. Introduction All of the following examples in this section will require two web pages. The first page retrieves information posted.](https://reader030.fdocuments.us/reader030/viewer/2022032415/56649f055503460f94c19b08/html5/thumbnails/14.jpg)
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.
![Page 15: CHAPTER 7 Form & PHP. Introduction All of the following examples in this section will require two web pages. The first page retrieves information posted.](https://reader030.fdocuments.us/reader030/viewer/2022032415/56649f055503460f94c19b08/html5/thumbnails/15.jpg)
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>
![Page 16: CHAPTER 7 Form & PHP. Introduction All of the following examples in this section will require two web pages. The first page retrieves information posted.](https://reader030.fdocuments.us/reader030/viewer/2022032415/56649f055503460f94c19b08/html5/thumbnails/16.jpg)
Getting Data from Form
checkboxes.php <html><head></head><body><?phpecho “$checkbox1<br>”;echo “$checkbox2<br>”;echo “$checkbox3<br>”;?></body></html>
![Page 17: CHAPTER 7 Form & PHP. Introduction All of the following examples in this section will require two web pages. The first page retrieves information posted.](https://reader030.fdocuments.us/reader030/viewer/2022032415/56649f055503460f94c19b08/html5/thumbnails/17.jpg)
Getting Data from Form
checkboxes.html
checkboxes.php
OracleSQLServer
![Page 18: CHAPTER 7 Form & PHP. Introduction All of the following examples in this section will require two web pages. The first page retrieves information posted.](https://reader030.fdocuments.us/reader030/viewer/2022032415/56649f055503460f94c19b08/html5/thumbnails/18.jpg)
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.
![Page 19: CHAPTER 7 Form & PHP. Introduction All of the following examples in this section will require two web pages. The first page retrieves information posted.](https://reader030.fdocuments.us/reader030/viewer/2022032415/56649f055503460f94c19b08/html5/thumbnails/19.jpg)
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>
![Page 20: CHAPTER 7 Form & PHP. Introduction All of the following examples in this section will require two web pages. The first page retrieves information posted.](https://reader030.fdocuments.us/reader030/viewer/2022032415/56649f055503460f94c19b08/html5/thumbnails/20.jpg)
Getting Data from Form
radiobutton.php
<html><head></head><body><? phpecho “you selected the answer :$radiobutton”;?></body></html>
![Page 21: CHAPTER 7 Form & PHP. Introduction All of the following examples in this section will require two web pages. The first page retrieves information posted.](https://reader030.fdocuments.us/reader030/viewer/2022032415/56649f055503460f94c19b08/html5/thumbnails/21.jpg)
Getting Data from Form
radiobutton.html
radiobutton.php
You selected the answer : Programming Language
![Page 22: CHAPTER 7 Form & PHP. Introduction All of the following examples in this section will require two web pages. The first page retrieves information posted.](https://reader030.fdocuments.us/reader030/viewer/2022032415/56649f055503460f94c19b08/html5/thumbnails/22.jpg)
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.
![Page 23: CHAPTER 7 Form & PHP. Introduction All of the following examples in this section will require two web pages. The first page retrieves information posted.](https://reader030.fdocuments.us/reader030/viewer/2022032415/56649f055503460f94c19b08/html5/thumbnails/23.jpg)
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>
![Page 24: CHAPTER 7 Form & PHP. Introduction All of the following examples in this section will require two web pages. The first page retrieves information posted.](https://reader030.fdocuments.us/reader030/viewer/2022032415/56649f055503460f94c19b08/html5/thumbnails/24.jpg)
Getting Data from Form
listbox.php
<html><head></head><body><?php echo “Price Range : $price" ;?></body></html>
![Page 25: CHAPTER 7 Form & PHP. Introduction All of the following examples in this section will require two web pages. The first page retrieves information posted.](https://reader030.fdocuments.us/reader030/viewer/2022032415/56649f055503460f94c19b08/html5/thumbnails/25.jpg)
Getting Data from Form
listboxes.html
listbox.php
Price Range: RM 3000- RM 3500
![Page 26: CHAPTER 7 Form & PHP. Introduction All of the following examples in this section will require two web pages. The first page retrieves information posted.](https://reader030.fdocuments.us/reader030/viewer/2022032415/56649f055503460f94c19b08/html5/thumbnails/26.jpg)
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.
![Page 27: CHAPTER 7 Form & PHP. Introduction All of the following examples in this section will require two web pages. The first page retrieves information posted.](https://reader030.fdocuments.us/reader030/viewer/2022032415/56649f055503460f94c19b08/html5/thumbnails/27.jpg)
Inserting Data from Form Into Database
form_complete.html
![Page 28: CHAPTER 7 Form & PHP. Introduction All of the following examples in this section will require two web pages. The first page retrieves information posted.](https://reader030.fdocuments.us/reader030/viewer/2022032415/56649f055503460f94c19b08/html5/thumbnails/28.jpg)
Inserting Data from Form Into Database
form_dbase.php
![Page 29: CHAPTER 7 Form & PHP. Introduction All of the following examples in this section will require two web pages. The first page retrieves information posted.](https://reader030.fdocuments.us/reader030/viewer/2022032415/56649f055503460f94c19b08/html5/thumbnails/29.jpg)
Inserting Data from Form Into Database
form_complete.html
![Page 30: CHAPTER 7 Form & PHP. Introduction All of the following examples in this section will require two web pages. The first page retrieves information posted.](https://reader030.fdocuments.us/reader030/viewer/2022032415/56649f055503460f94c19b08/html5/thumbnails/30.jpg)
Inserting Data from Form Into Database
Database content
Table
Database