By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,086 Members | 1,452 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,086 IT Pros & Developers. It's quick & easy.

Undefinded index using $_POST ...

P: n/a
Hello, I'm just getting starting in php and MySQL and I've got my
application working correctly on my local windows XP computer. Now, when I
publish to my ISP it's not going so well, which is also a Windows server.

I'm using form variables to control navigating to different pages when a
page is reloaded. As I said no problem on my machine but on the ISP server
I'm getting the following messages snd of course it's not working. Both
systems are running php version 4.3.10.

Thank you for any help provided because I'm really stumped!

Vic
Notice: Undefined index: Home in
d:\html\users\149999\mydomaincom\html\myfolder\Mem ber_Page.php on line 11
Notice: Undefined index: Clear in
d:\html\users\149999\mydomaincom\html\myfolder\Mem ber_Page.php on line 14
Notice: Undefined index: Update in
d:\html\users\149999\mydomaincom\html\myfolder\Mem ber_Page.php on line 16
Notice: Undefined variable: button in
d:\html\users\149999\mydomaincom\html\myfolder\Mem ber_Page.php on line 24
Notice: Undefined index: do in
d:\html\users\149999\mydomaincom\html\myfolder\Mem ber_Page.php on line 187

if ($_POST['Home'])
{
$button = "Home"; }
else if ($_POST['Clear']) {
$button = "Clear"; }
else if ($_POST['Update']) {
$button = "Update"; }

switch ($button)
{
case "Clear":
if (isset($selectedRow))
unset ($selectedRow);
$items = 1;
$street2 = " ";
$comments= " ";
$OriginAirport="PDX";
$searchState = "Oregon";
$message_new = "New Item? Please complete following fields:";
include("BagDetail_form.inc");
break;

case "Home":
// Load the Home Page
$_SESSION['auth']="yes";
$_SESSION['logname'] = $newname;
header("Location: index.php");
break;

case "Update":

foreach($_POST as $field => $value)
{
if ($field != "email" and $field !="street2" and $field
!="comments")
Jul 17 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Vic Spainhower wrote:

Hi Vic,
Hello, I'm just getting starting in php and MySQL and I've got my
application working correctly on my local windows XP computer. Now, when I
publish to my ISP it's not going so well, which is also a Windows server.

I'm using form variables to control navigating to different pages when a
page is reloaded. As I said no problem on my machine but on the ISP server
I'm getting the following messages snd of course it's not working. Both
systems are running php version 4.3.10.

Thank you for any help provided because I'm really stumped!

Vic
Notice: Undefined index: Home in
d:\html\users\149999\mydomaincom\html\myfolder\Mem ber_Page.php on line 11
Notice: Undefined index: Clear in
d:\html\users\149999\mydomaincom\html\myfolder\Mem ber_Page.php on line 14
Notice: Undefined index: Update in
d:\html\users\149999\mydomaincom\html\myfolder\Mem ber_Page.php on line 16
Notice: Undefined variable: button in
d:\html\users\149999\mydomaincom\html\myfolder\Mem ber_Page.php on line 24
Notice: Undefined index: do in
d:\html\users\149999\mydomaincom\html\myfolder\Mem ber_Page.php on line 187

if ($_POST['Home'])


Alway use:
if (isset($_POST["home"]))

to check if a a variable (in an array or not) exists.

I think if you rewrite your code accordingly, you are out of notices.
:-)

Good luck!

Regards,
Erwin Moller
Jul 17 '05 #2

P: n/a
Erwin,

Thank you very much that was the problem! Would it be the error reporting
level is different between my system and my ISP's server which is why it
appeared to work on my system?

Thanks,

Vic
"Erwin Moller"
<si******************************************@spam yourself.com> wrote in
message news:42***********************@news.xs4all.nl...
Vic Spainhower wrote:

Hi Vic,
Hello, I'm just getting starting in php and MySQL and I've got my
application working correctly on my local windows XP computer. Now, when
I
publish to my ISP it's not going so well, which is also a Windows server.

I'm using form variables to control navigating to different pages when a
page is reloaded. As I said no problem on my machine but on the ISP
server
I'm getting the following messages snd of course it's not working. Both
systems are running php version 4.3.10.

Thank you for any help provided because I'm really stumped!

Vic
Notice: Undefined index: Home in
d:\html\users\149999\mydomaincom\html\myfolder\Mem ber_Page.php on line 11
Notice: Undefined index: Clear in
d:\html\users\149999\mydomaincom\html\myfolder\Mem ber_Page.php on line 14
Notice: Undefined index: Update in
d:\html\users\149999\mydomaincom\html\myfolder\Mem ber_Page.php on line 16
Notice: Undefined variable: button in
d:\html\users\149999\mydomaincom\html\myfolder\Mem ber_Page.php on line 24
Notice: Undefined index: do in
d:\html\users\149999\mydomaincom\html\myfolder\Mem ber_Page.php on line
187

if ($_POST['Home'])


Alway use:
if (isset($_POST["home"]))

to check if a a variable (in an array or not) exists.

I think if you rewrite your code accordingly, you are out of notices.
:-)

Good luck!

Regards,
Erwin Moller

Jul 17 '05 #3

P: n/a
.oO(Vic Spainhower)
Thank you very much that was the problem! Would it be the error reporting
level is different between my system and my ISP's server which is why it
appeared to work on my system?


Yep. The default error_reporting doesn't show notices. You should set it
to E_ALL in your php.ini.

Micha
Jul 17 '05 #4

P: n/a
Erwin Moller wrote:


if ($_POST['Home'])


Alway use:
if (isset($_POST["home"]))

to check if a a variable (in an array or not) exists.

I think if you rewrite your code accordingly, you are out of notices.
:-)


....and to go further, you can wrap it:

function PostSafe($key,$default="",$report_bad_key=true) {
if (isset($_POST[$key])) { return MySanitizer($_POST[$key]); }

if ($report_bad_key) {
ErrorAdd("Attempt to retrieve non-existent post key: $key");
}
return $default;
}

so a normal call is:

$home = PostSafe("Home");

and you can also provide a default and suppress error reporting on optional
values:

$myvar = PostSafe("optional_variable","default_value",false );

--
Kenneth Downs
Secure Data Software, Inc.
(Ken)nneth@(Sec)ure(Dat)a(.com)
Jul 17 '05 #5

P: n/a
"Vic Spainhower" <vi*@showsec.com> wrote in message
news:IJ********************@comcast.com...
Hello, I'm just getting starting in php and MySQL and I've got my
application working correctly on my local windows XP computer. Now, when I
publish to my ISP it's not going so well, which is also a Windows server.

I'm using form variables to control navigating to different pages when a
page is reloaded. As I said no problem on my machine but on the ISP server
I'm getting the following messages snd of course it's not working. Both
systems are running php version 4.3.10.

Thank you for any help provided because I'm really stumped!


Just stick a @ in front of $_POST[] to supress the notice:

if(@$_POST['Home']) {
}
Jul 17 '05 #6

P: n/a
Chung Leong wrote:
"Vic Spainhower" <vi*@showsec.com> wrote in message
news:IJ********************@comcast.com...
Hello, I'm just getting starting in php and MySQL and I've got my
application working correctly on my local windows XP computer. Now, when
I publish to my ISP it's not going so well, which is also a Windows
server.

I'm using form variables to control navigating to different pages when a
page is reloaded. As I said no problem on my machine but on the ISP
server I'm getting the following messages snd of course it's not working.
Both systems are running php version 4.3.10.

Thank you for any help provided because I'm really stumped!


Just stick a @ in front of $_POST[] to supress the notice:

if(@$_POST['Home']) {
}


Yes, it supresses the error, but I do not like that approach.
IMHO it is better to branch your code, so you know if the posting contains
the things you expect.

But it will depend on the situation if you get away with it.

(Just my 2 cents, I am not saying you are wrong.)

Regards,
Erwin Moller
Jul 17 '05 #7

P: n/a
I noticed that Message-ID: <42***********************@news.xs4all.nl>
from Erwin Moller contained the following:
if(@$_POST['Home']) {
}


Yes, it supresses the error, but I do not like that approach.
IMHO it is better to branch your code, so you know if the posting contains
the things you expect.

I suspect Chung is being playful
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #8

P: n/a
"Erwin Moller"
<si******************************************@spam yourself.com> wrote in
message news:42***********************@news.xs4all.nl...
Chung Leong wrote:
"Vic Spainhower" <vi*@showsec.com> wrote in message
news:IJ********************@comcast.com...
Hello, I'm just getting starting in php and MySQL and I've got my
application working correctly on my local windows XP computer. Now, when I publish to my ISP it's not going so well, which is also a Windows
server.

I'm using form variables to control navigating to different pages when a page is reloaded. As I said no problem on my machine but on the ISP
server I'm getting the following messages snd of course it's not working. Both systems are running php version 4.3.10.

Thank you for any help provided because I'm really stumped!


Just stick a @ in front of $_POST[] to supress the notice:

if(@$_POST['Home']) {
}


Yes, it supresses the error, but I do not like that approach.
IMHO it is better to branch your code, so you know if the posting contains
the things you expect.


Notices and warnings are not error. They're advisory messages that indicate
the *possibility* of a programming error. If triggered by something that
done by design, then they should simply be ignored. There is no point in
coding around false positives.

In this case, the absence of the field 'Home' is expected (hence the if
statement), so it is not a programming error.
Jul 17 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.