Undefined index??

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jiehuang001
Forum Commoner
Posts: 39
Joined: Mon May 12, 2003 12:53 pm

Undefined index??

Post by jiehuang001 »

Hi, I have a very simple php page abc.php like this:
<?php
$Module_id = $_POST['module_id'];
echo $Module_id;
?>

However, when I type http://localhost/abc.php?module_id=1,
I got this error:
"Undefined index: module_id in abc.php"

Can someone tell me what is wrong?

Thanks.

Jie Huang
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

appending parameters to the url is called GET-method.
PHP stores them in $_GET
http://www.php.net/manual/en/reserved.v ... iables.get
Gleeb
Forum Commoner
Posts: 87
Joined: Tue May 13, 2003 7:01 am
Location: UK
Contact:

Re: Undefined index??

Post by Gleeb »

jiehuang001 wrote:Hi, I have a very simple php page abc.php like this:
<?php
$Module_id = $_POST['module_id'];
echo $Module_id;
?>

However, when I type http://localhost/abc.php?module_id=1,
I got this error:
"Undefined index: module_id in abc.php"

Can someone tell me what is wrong?

Thanks.

Jie Huang
$_POST only works on POSTed information. When the information is part of the URL, use $_GET. For example :-

Code: Select all

<?php
	$Module_id = $_GET['module_id'];
	echo $Module_id;
?>
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

Post by AVATAr »

Introduced in php 4.1.0. you can use $_REQUEST['module_id'] if you dont know the method you are using (post or get)...
Post Reply