开发者

How to pick up form details using POST request from a PHP page which was accessed using GET request

I have executed a php script through GET request ex:

http://localhost/example.php?id=9&name=exammple

Now the example.php has a form field

<form method="post" action="example.php">

---form f开发者_StackOverflow社区ields used to post data on server---

</form>

Now on submitting the form, it throws up an error saying undefined indexes.

How do I submit a form in a page which was accessed using GET request? I am a PHP beginner.


Use <form method="post" action=""> Then it will post the data to the same page (with the GET parameters) and you can get them using $_GET and the parameters from the form using $_POST or all with $_REQUEST.


Add a

$_POST += $_GET;

before you access the $_POST variables or use anther request variable like $_REQUESTDocs if you want to allow others next to $_GET, too (namely $_COOKIES with PHP's default configuration).

A little explanation:

  • $_GET - contains all get variables.
  • $_POST - contains all post variables.

The

$_POST += $_GET;

will put all get variables into $_POST if they have not been send as post variable by creating a union of $_POST and $_GET.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜