Form submission method
1. GET Method
Function: get the data submitted in get mode.
Format: $ _ GET ["formelement"]
2. POST Method
Function: obtains the data submitted in post mode.
Format: $ _ POST ["formelement"]
3. REQUEST Method
Function: obtain data submitted in any way
Format: $ _ REQUEST ["formelement"]
Check box, list box (the name is in the form of an array, such as: "select []", you can directly use $ _ POST ["select"] when getting its value) with example Sub:
Add page -- list box:
<Form id = "form1" name = "form1" method = "post" action = "action2.php">
<Label>
<Select name = "selt []" size = "13" multiple = "multiple" id = "selt []">
<Option value = "sdad"> eewew </option>
<Option value = "12"> 12 </option>
<Option value = "13"> 13 </option>
<Option value = "15"> 15 </option>
<Option value = "16"> 16 </option>
</Select>
</Label>
<Label>
<Input type = "submit" name = "Submit" value = "submit"/>
</Label>
</Form>
Receiving page:
<?
# Echo $ _ POST ["selt"]
Print_r ($ _ POST ["selt"]);
?>
Check box: add page:
<Form id = "form1" name = "form1" method = "post" action = "action. php">
<Label>
<Input name = "chkval []" type = "checkbox" id = "chkval []" value = "1"/>
</Label>
1212
<P>
<Label>
<Input name = "chkval []" type = "checkbox" id = "chkval []" value = "2"/>
</Label>
</P> 2121
<P>
<Label>
<Input name = "chkval []" type = "checkbox" id = "chkval []" value = "3"/>
</Label>
</P> 11212
<P>
<Label>
<Input type = "submit" name = "Submit" value = "submit"/>
</Label>
</P>
</Form>
Receiving page:
<?
# Echo $ _ POST ["username"];
# Echo $ _ GET ["username"];
# Echo $ _ REQUEST ["username"]
# Echo $ username;
// Echo $ _ POST ["chkval"];
Print_r ($ _ POST ["chkval"]);
?>
1. Get the value in the text box: $ _ POST ["text"]
Here, you can check whether the magic switch is on (enabled by default). If not, you can use addslashes ($ _ POST ["text"]) to format it in HTML, the statement is as follows:
If (get_magic_quotes_gpc ())
{
// Enabled
Echo "enabled <p> ";
Echo stripslashes ($ _ POST ["text"]);
}
Else
{
Echo addslashes ($ _ POST ["text"]);
}
2. File Upload:
File Upload code:
$ F = $ _ FILES ['files'];
$ Dest_dir = 'uploads'; // sets the upload directory.
$ Dest = $ dest_dir. '/'. $ f ['name']; // set the file name
$ R = move_uploaded_file ($ f ['tmp _ name'], $ dest );
# Chmod ($ dest, 0755); // sets the attributes of the uploaded file
Move_uploaded_file ($ file, $ destc)
Move the uploaded file to a new location
Upload_file.php
<Body>
<Form action = "upload. php" method = "post" enctype = "multipart/form-data" name = "form1" id = "form1">
<Label>
<Input name = "fls" type = "file" id = "fls"/>
</Label>
<Label>
<Input type = "submit" name = "Submit" value = "submit"/>
</Label>
<P>
<Label> </label>
</P>
</Form>
Upload. php
<?
# Echo $ _ FILES ["fls"];
# Print_r ($ _ FILES ["fls"]);
// Echo $ _ FILES ["fls"] ["name"]; www.2cto.com
$ F = $ _ FILES ["fls"]; // obtain the value in the file box.
$ Dest_dir = "uploads"; // sets the upload directory.
$ Dest = $ dest_dir. "/". date ("ymdhji"). $ f ["name"]; // set the file name
Move_uploaded_file ($ f ["tmp_name"], $ dest );
# Move_uploaded_file ()
?>
From hurry's column