Download - Form & PHP

Transcript
Page 1: Form & PHP

Form & PHP

Page 2: 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.

• 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: Form & PHP

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: Form & PHP

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: Form & PHP

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: Form & PHP

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: Form & PHP

Getting Data from Form

Text Fields (text boxes)• Text fields are created using <input> element• Setting type attribute to text

Page 8: Form & PHP

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: Form & PHP

Getting Data from Form

textfield.html

textfield.php

My name is hani

Page 10: Form & PHP

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: Form & PHP

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: Form & PHP

Getting Data from Form

 textarea.php <html><head></head><body>My favourite HTML editor are: <? php echo $editor ; ?></body></html>

Page 13: Form & PHP

Getting Data from Form

textarea.html

textarea.php

My favourite HTML editor are :Ultra Edit Visual Interdev

Note Pad Crimson Editor

Page 14: Form & PHP

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: Form & PHP

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: Form & PHP

Getting Data from Form

 checkboxes.php <html><head></head><body><?phpecho “$checkbox1<br>”;echo “$checkbox2<br>”;echo “$checkbox3<br>”;?></body></html>

Page 17: Form & PHP

Getting Data from Form

checkboxes.html

checkboxes.php

OracleSQLServer

Page 18: Form & PHP

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: Form & PHP

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: Form & PHP

Getting Data from Form

 radiobutton.php

<html><head></head><body><? phpecho “you selected the answer :$radiobutton”;?></body></html>

Page 21: Form & PHP

Getting Data from Form

radiobutton.html

radiobutton.php

You selected the answer : Programming Language

Page 22: Form & PHP

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: Form & PHP

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: Form & PHP

Getting Data from Form

 listbox.php

<html><head></head><body><?php echo “Price Range : $price" ;?></body></html>

Page 25: Form & PHP

Getting Data from Form

listboxes.html

listbox.php

Price Range: RM 3000- RM 3500

Page 26: Form & PHP

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: Form & PHP

Inserting Data from Form Into Database

form_complete.html

Page 28: Form & PHP

Inserting Data from Form Into Database

form_dbase.php

Page 29: Form & PHP

Inserting Data from Form Into Database

form_complete.html

Page 30: Form & PHP

Inserting Data from Form Into Database

Database content

Table

Database


Top Related