Newbie: Undefined index: ..= $HTTP_POST_VARS["hook"

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
fopetesl
Forum Newbie
Posts: 7
Joined: Mon Oct 11, 2004 1:45 pm
Location: Yorkshire Dales UK

Newbie: Undefined index: ..= $HTTP_POST_VARS["hook"

Post by fopetesl »

I am at something of a loss as to how to dig this one out. The same php script on a Mandrake 10 machine runs fine but on the Ubuntu machine I get the error/warning:

Code: Select all

Notice: Undefined index: hook in /var/www/html/processData.php on line 9 
8
9
   $hook   = $HTTP_POST_VARS["hook"];
10
   if(isset($parameter0)) $parameter0 = $HTTP_POST_VARS["parameter0"];
The actual script begins:

Code: Select all

<?php

   include "debugHelper.php";

   //  Updated:      28/03/2006  @ 14:45

   //  ACQUIRE FLASH VARIABLES HERE AND TURN THEM INTO PHP VARIABLES

   $hook   = $HTTP_POST_VARS["hook"];
   if(isset($parameter0)) $parameter0 = $HTTP_POST_VARS["parameter0"];
   if(isset($parameter1)) $parameter1 = $HTTP_POST_VARS["parameter1"];
I obviously do not have a global? variable set somewhere.

BTW this script is meant to be called from a Flash GUI but when I attempt to run the GUI it fails without any traceable error. (It runs fine on MDK10) Are the trwo problems connected or is it merely a PHP problem?
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

This is becuase on this installation, error reporting is set to a higher level.

Basically, to rectify the problem your code code look something like this

Code: Select all

if(isset($HTTP_POST_VARS["hook"]))
{
    $hook = $HTTP_POST_VARS["hook"]; 
}
else
{
   echo "hook is not set";
}
fopetesl
Forum Newbie
Posts: 7
Joined: Mon Oct 11, 2004 1:45 pm
Location: Yorkshire Dales UK

Yo! That one's cured but ...

Post by fopetesl »

I now have a problem in loading the GUI and running MySql query.

Cured the above by 'calling' the php script from the GUI. That undefined variable appears to be supplied by the GUI(?).

Am checking MySql permissions .. more later TY pimp'
yamobe
Forum Newbie
Posts: 13
Joined: Mon Jun 19, 2006 9:42 am

Post by yamobe »

another way to make it work is to replace $HTTP_POST_VARS by $_POST.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

yamobe wrote:another way to make it work is to replace $HTTP_POST_VARS by $_POST.
That wouldn't solve the first Notice.
fopetesl
Forum Newbie
Posts: 7
Joined: Mon Oct 11, 2004 1:45 pm
Location: Yorkshire Dales UK

One step further ...

Post by fopetesl »

Now attempting to run script from GUI i get:

Code: Select all

Error: Can't access network
and when I look in apache/error.log:

Code: Select all

[Tue Jun 20 16:05:51 2006] [error] [client 127.0.0.1] script '/var/www/processData.php' not found or unable to stat, referer: http://127.0.0.1/html/gui.swf
Please note: processData.php is actually in /var/www/html/ directory together with gui.swf, not in /var/www/ directory. These proggies run just fine on an older Mandrake10 machine from the /../html/ directory.

Somewhere I do not have a path set correctly but after hours of searching I cannot discover just where.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

did you try this?

Code: Select all

include('html/processData.php');
fopetesl
Forum Newbie
Posts: 7
Joined: Mon Oct 11, 2004 1:45 pm
Location: Yorkshire Dales UK

Post by fopetesl »

Ummm. Include in what? Write another php script in ../html/ ?
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Re: Newbie: Undefined index: ..= $HTTP_POST_VARS["hook&

Post by Luke »

Code: Select all

<?php

   include "html/debugHelper.php"; // Right here

   //  Updated:      28/03/2006  @ 14:45

   //  ACQUIRE FLASH VARIABLES HERE AND TURN THEM INTO PHP VARIABLES

   $hook   = $HTTP_POST_VARS["hook"];
   if(isset($parameter0)) $parameter0 = $HTTP_POST_VARS["parameter0"];
   if(isset($parameter1)) $parameter1 = $HTTP_POST_VARS["parameter1"];
fopetesl
Forum Newbie
Posts: 7
Joined: Mon Oct 11, 2004 1:45 pm
Location: Yorkshire Dales UK

Post by fopetesl »

OK. Call me a thicko then but if apache/localhost/gui.swf cannot find ProCessData.php in the ../html/ directory how is it/them going to catch the "include" statement? Note there are no errors regarding debugHelper.php .. Yet.
Robert Plank
Forum Contributor
Posts: 110
Joined: Sun Dec 26, 2004 9:04 pm
Contact:

Post by Robert Plank »

To take care of the undefined index notice you should be checking for array_key_exists before using an array subscript.

Like:

Code: Select all

if (array_key_exists("hook", $_POST)) {
   $hook   = $_POST["hook"];
}
Post Reply