Portrety Uliczne Nieznajomych - zobacz wyjątkową galerię portretów z warszawskich ulic
ZALOGUJ SIĘ
login:
hasło:
przypomnij hasło
załóż konto użytkownika
(i zobacz kilka porad gratis)
   
WYSZUKIWARKA I DZIAŁY
całe porady  tytuły
zaznacz działy do przeszukania
(brak wyboru = wszystkie działy)
PHP
MySQL >
PostgreSQL
SQLite
Perl
Java
XML
XSLT
XPath
WML
SVG
RegExp
Wyszukiwarki
Ochrona
VBScript
Google Plus
XHTML/CSS
JavaScript
Grafika
Flash
Photoshop
Windows
Linux
Bash
Apache
Procmail
E-biznes
Explorer
Opera
Firefox
Inne porady
   
KURSY, DOKUMENTACJE
Własne:
XHTML/CSS
JavaScript
ActionScript
WML, RSS, SSI
Pozostałe:
PHP
MySQL
Java API
więcej...
   
użytkowników online: 68
W CZYM MOGĘ POMÓC?


   
OPINIE UŻYTKOWNIKÓW
Gratulacje i dzięki! Trafiłem tu przypadkiem poszukując informacji na temat php+mysql. Wiele polskich stron powiela identyczne przykłady, klonuje te same kursy i lekcje... ten serwis okazał sie inny. Zasada "problem - rozwiazanie - wyjaśnienie" zdaje egzamin - zapewnia jasną, jednoznaczną i pewną pomoc w konkretnym przypadku. Porady są warte swojej ceny, przede wszystkim ze względu na przyjazną (także dla początkujących) formę i treść oraz bogate i stale powiększane zasoby. Polecam i pozdrawiam!

Kamil Dmowski
Polski Czerwony Krzyż

   
GALERIA FOTOGRAFII
   
PODRĘCZNIK PHP 5.x, 4.x, 3.x - częściowo spolszczony / źródło: www.php.net

[Spis] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [X] [W] [Z]

PHP i formularze

Obsługa formularzy HTML to jedno z podstawowych zadań skryptów PHP. Najprościej mówiąc, wartości wszystkich elementów formularza (pól tekstowych, pól checkbox i radio, list rozwijanych itp.) są automatycznie udostępniane skryptom PHP. Przykłady i informacje na ten temat znajdziesz w sekcji Zmienne spoza PHP. Oto przykładowy formularz HTML:

Przykład 2-6. Prosty formularz HTML

<form action="action.php" method="post">
 Twoje imię: <input type="text" name="imie" />
 Data urodzenia: <input type="text" name="rok" />
 <input type="submit" />
</form>

Nie ma tu nic niezwykłego. To po prostu zwyczajny formularz zbudowany ze standardowych znaczników języka HTML. Gdy użytkownik wypełni pola tekstowe i kliknie przycisk, informacje zostaną przesłane do skryptu action.php. W tym pliku mógłbyś umieścić coś takiego:

Przykład 2-7. Wyświetlanie danych z formularza

Cześć <?php echo $_POST['imie']; ?>.
Urodziłeś się w <?php echo $_POST['rok']; ?> roku.

Wynikiem wykonania takiego skryptu może być:

Cześć Zenek. Urodziłeś się w 1980 roku.

Chyba nie trzeba tłumaczyć do czego służy powyższy skrypt. Zmienne $_POST['imie'] i $_POST['rok'] są automatycznie ustawiane po przesłaniu formularza przez użytkownika. Wcześniej użyliśmy zmiennej superglobalnej $_SERVER; teraz poznaliśmy zmienną $_POST (również superglobalną), która przechowuje wszystkie dane wysłane w formularzu. Zauważ, że nasz formularz przekazywany jest metodą POST (parametr method). Jeśli wybralibyśmy metodę GET, wszystkie dane znajdowały się w zmiennej superglobalnej $_GET. Ostatecznie możesz również skorzystać ze zmiennej $_REQUEST, jeśli nie interesuje cię to, skąd pochodzą przesłane dane. Zmienna ta zawiera wszystkie informacje niezależnie od tego czy zostały one przekazane metodą GET, POST czy też w ciasteczku (cookie). Przyjrzyj się też funkcji import_request_variables().




User Contributed Notes

20-Jun-2005 12:49

===
According to the HTTP specification, you should use the POST method when you're using the form to change the state of something on the server end. For example, if a page has a form to allow users to add their own comments, like this page here, the form should use POST. If you click "Reload" or "Refresh" on a page that you reached through a POST, it's almost always an error -- you shouldn't be posting the same comment twice -- which is why these pages aren't bookmarked or cached.

You should use the GET method when your form is, well, getting something off the server and not actually changing anything.  For example, the form for a search engine should use GET, since searching a Web site should not be changing anything that the client might care about, and bookmarking or caching the results of a search-engine query is just as useful as bookmarking or caching a static HTML page.
====

Indeed. It's not smart to say the least, to do database manipulation trough querystring whatsoever.


yasman at phplatvia dot lv
05-May-2005 09:18

Be careful, when using and processing forms which contains
<input type="image">
tag. Do not use in your scripts this elements attributes `name` and `value`, because MSIE and Opera do not send them to server.
Both are sending `name.x` and `name.y` coordiante variables to a server, so better use them.


grant_floyd at yahoo dot not dot yohoo dot com
22-Apr-2004 06:54

Refering to the GET/POST usage in the HTML specification mentioned:

Although GET will normally be used for requesting information from a webserver the length of the URL is limited to a maximum number of characters. So if you have a form which submits lots of information and text selections you will have to use a POST.

Likewise, sometimes it doesn't make any sense to create a form with a POST method to do something to the server.

For example, if you have a website with a list of users and you want to select one of them to delete, each username could be a 'Delete user' link.  It is easier to create a link called /website/deleteuser.php?id=<userid> for each, where deleteuser.php contains the (pseudocode):

$sql = "DELETE FROM usertable WHERE id = " . (int) $_GET['id'];

Finally, $_REQUEST is the simplest default retrieval method as it combines GET, POST and COOKIE information. One thing to be aware of is that it combines the information in an order of precedence defined by the server.

For example, if a website has a cookie with $username and you make up a POST form and use a variable '$username' you may get the $_POST['username'] value instead of the $_COOKIE['username'], causing you some confusion.

The order is defined on the server as 'variables_order'. This set the order of the EGPCS (Environment, GET, POST, Cookie, Server) variable parsing. The default setting of this directive is "EGPCS". So in the above example 'P' for POST comes before 'C' for COOKIE.


sethg at ropine dot com
01-Dec-2003 09:55

According to the HTTP specification, you should use the POST method when you're using the form to change the state of something on the server end. For example, if a page has a form to allow users to add their own comments, like this page here, the form should use POST. If you click "Reload" or "Refresh" on a page that you reached through a POST, it's almost always an error -- you shouldn't be posting the same comment twice -- which is why these pages aren't bookmarked or cached.

You should use the GET method when your form is, well, getting something off the server and not actually changing anything.  For example, the form for a search engine should use GET, since searching a Web site should not be changing anything that the client might care about, and bookmarking or caching the results of a search-engine query is just as useful as bookmarking or caching a static HTML page.


 

 
  © 1996-2012 & Reporter.plmiejscao serwisieabonamentwarunki korzystaniaRSSkontakt