Undefined Index (won't go away)

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
User avatar
Templeton Peck
Forum Commoner
Posts: 45
Joined: Sun May 11, 2003 7:51 pm

Undefined Index (won't go away)

Post by Templeton Peck »

Notice: Undefined index: submit in C:\Program Files\Apache Group\Apache2\htdocs\test.php on line 27

which is this line if($_POST['submit'] != false)


and this is the submit its referring to:
<input type = "submit" name = 'submit' value = 'Expand'/>

any ideas why it won't work please?
Coco
Forum Contributor
Posts: 339
Joined: Sat Sep 07, 2002 5:28 am
Location: Leeds, UK
Contact:

Post by Coco »

not meaning to hijack someone elses thread... but im having the same problem :( (this is being a rather bad night for me :( )

i have this:

Code: Select all

<?php
$message = str_replace("<#c_id#>",AddSlashes($id),$message);
$message = str_replace("<#c_name#>",AddSlashes($HTTP_POST_VARS['rlname']),$message);
$message = str_replace("<#c_nick#>",AddSlashes($HTTP_POST_VARS['username']),$message);
$message = str_replace("<#c_country#>",AddSlashes($countries[$HTTP_POST_VARS['country']]),$message);
$message = str_replace("<#c_icq#>",AddSlashes($HTTP_POST_VARS['icq']),$message);
$message = str_replace("<#c_email#>",AddSlashes($HTTP_POST_VARS['email']),$message);
$message = str_replace("<#c_password#>",AddSlashes($HTTP_POST_VARS['pass1']),$message);
$message = str_replace("<#c_sitename#>",$setupvars['sitename'],$message);
$message = str_replace("<#c_siteurl#>",$setupvars['siteurl'],$message);
$message = str_replace("<#c_adminemail#>",$setupvars['adminemail'],$message);  
$message = str_replace("<#c_forums#>",$setupvars['forums'],$message);
                
$subject = "Registration confirmation For User $HTTP_POST_VARS['username']"; //******line 37
mail($HTTP_POST_VARS['email'],$subject,$message,"From:$setupvars['sitename'] <$setupvars['adminemail']>\nReplyTo:$setupvars['adminemail']");
?>
and the error is:
Notice: Undefined index: 'username' in c:\program files\apache group\apache\htdocs\stuff\lite\include\userbadconf.php on line 37

Notice: Undefined index: 'sitename' in c:\program files\apache group\apache\htdocs\stuff\lite\include\userbadconf.php on line 38

Notice: Undefined index: 'adminemail' in c:\program files\apache group\apache\htdocs\stuff\lite\include\userbadconf.php on line 38

Notice: Undefined index: 'adminemail' in c:\program files\apache group\apache\htdocs\stuff\lite\include\userbadconf.php on line 38


so hows come im getting undefined index on index's that have just been used without an error?
Coco
Forum Contributor
Posts: 339
Joined: Sat Sep 07, 2002 5:28 am
Location: Leeds, UK
Contact:

Post by Coco »

oh and templeton.. you can always print_r($_POST) to check what you have :)
User avatar
Templeton Peck
Forum Commoner
Posts: 45
Joined: Sun May 11, 2003 7:51 pm

Post by Templeton Peck »

The thing is my program works right, the way its supposed to. BUT I still get that error when I start.. once I hit that submit button once the error goes away. (if I reset it back though, there is the error again)
Coco
Forum Contributor
Posts: 339
Joined: Sat Sep 07, 2002 5:28 am
Location: Leeds, UK
Contact:

Post by Coco »

ahh ok thats because theres no $_POST array.... so it gives a warning (which you can supress)
i suggest you might want to try changing it to
if(isset($_POST['submit']))
User avatar
Templeton Peck
Forum Commoner
Posts: 45
Joined: Sun May 11, 2003 7:51 pm

Post by Templeton Peck »

that did the trick man! thanks appreciate it :)
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Coco: You're trying to nest string literals by
$subject = "Registration confirmation For User $HTTP_POST_VARS['username']";
try

Code: Select all

$subject = "Registration confirmation For User $HTTP_POST_VARS[username]";
or

Code: Select all

$subject = 'Registration confirmation For User '. $HTTP_POST_VARS['username'];
instead


But I'm still puzzled

Code: Select all

<?php
$arr = array("'test'" => 'valid');
echo "since when is this $arr['test'] ?";
?>
I'm quite sure this gave a parse error not long ago....
Post Reply