473,378 Members | 1,536 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Undefinded index using $_POST ...

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
8 2192
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
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
.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
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
"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
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
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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: news.bigpond.com | last post by:
getting errors Notice: Undefined index: name in F:\uni\Software engineering\assignment4\guestbook.php on line 6 the variable $name is declared as $name = _POST; What could be causing this?...
4
by: John Oliver | last post by:
PHP Notice: Undefined index: name in /home/www/reformcagunlaws.com/new.php on line 6 PHP Notice: Undefined index: address in /home/www/reformcagunlaws.com/new.php on line 7 PHP Notice: ...
3
by: tyngtyng | last post by:
hi... i'm new to the php and now i'm getting an error to insert my data inside the form..and also undefined index in latest_updated...... Now,i'm having trouble catching what i'm doing...
12
by: bb nicole | last post by:
I have do a update profile for company where they can update after view their profile, but it cannot function... I need to submit the whole job portal soon, but still got many problem in my coding,...
3
cassbiz
by: cassbiz | last post by:
Here are the errors that are coming up in my error_log Notice: Undefined index: andatum in /zipcode.php on line 11 Notice: Undefined index: andatum in /zipcode.php on line 12 Notice: Undefined...
6
by: sgottenyc | last post by:
Hello, If you could assist me with the following situation, I would be very grateful. I have a table of data retrieved from database displayed on screen. To each row of data, I have added...
3
by: number1yan | last post by:
Can anyone help me, i am creating a website and am using a php script that recomends the website to other people. I keep getting the same error and can not work out why. The error is: Notice:...
3
by: JJM0926 | last post by:
I've got a contact form with a submit button where users have to enter their support information. Some fields are required some are not. When I test out the form if I leave everything blank I get...
4
by: cyberlei | last post by:
hi all, I`m getting this error Notice: Undefined index: user in c:\inetpub\wwwroot\login.php on line 96 Notice: Undefined variable: message in c:\inetpub\wwwroot\login.php on line 101 Could...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.