[PHP] Re: Undefined index....

2013-03-15 Thread Tim Streater
On 15 Mar 2013 at 13:10, Jay Blanchard jay.blanch...@sigmaphinothing.org 
wrote: 

 I have inherited a mess of a home-grown PHP framework that literally
 fills the error_log with 100's of thousands of messages each day. First
 order of business was rotating the logs, now we are working through each
 error to solve them. This is a fairly basic error, but I for the life of
 me cannot remember what the solution is.

 I have a recursive function that reads from XML files and replaces xi:
 include directives. It looks like this -

 function includeXML($file, $locale, $url, $level = 1) {
 // stuff
 while(($line = fgets($fp)) !== false) {
 if($pos === false) {
 $xml .= $line;
 } else {
 includeXML('repository/' . $included, $locale, (int)$level
 + $pos - 1);
 }
 }
 }

 Why do I get the notice that $xml is an undefined index?

Because it's undefined. So is $pos. From what you've written above, both are 
local to includeXML. But neither is passed in as a parameter, nor is global. 
You can't initialise it within the function, it seems to me.

If $xml is supposed to be appended to and grown as you recurse up and down, 
then you have two choices:

1) Make them global
2) Pass both as extra parameters to includeXML

In both cases, each needs to be initialised before the first call to the 
recursive function

Solution (1)


$xml = '';
$pos = 0;// Presumably.
includeXML ($file, $locale, $url, 1);

...

function includeXML ($file, $locale, $url, $level = 1) {

global  $xml, $pos;

// stuff
while(($line = fgets($fp)) !== false) {
if($pos === false) {
$xml .= $line;
} else {
includeXML ('repository/' . $included, $locale, (int)$level
+ $pos - 1);
}
}
}

Solution (2)


$xml = '';
$pos = 0;// Presumably.
includeXML ($xml, $pos, $file, $locale, $url, 1);

...

function includeXML ($xml, $pos, $file, $locale, $url, $level = 1) {// 
Note the  on the first parameter
// stuff
while(($line = fgets($fp)) !== false) {
if($pos === false) {
$xml .= $line;
} else {
includeXML ($xml, $pos, 'repository/' . $included, $locale, 
(int)$level
+ $pos - 1);
}
}
}


BTW it seems to me that you'll have the same problem with $included unless 
there's other code in includeXML that you've omitted.

--
Cheers  --  Tim

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

[PHP] Re: Undefined Index ...confusion

2009-07-23 Thread Peter Ford
Miller, Terion wrote:
 I keep getting this error while trying to use the field 'ID' to pass in a 
 url.. And it's odd because the query is pulling everything BUT the ID which 
 is the first field...
 
 code:
 a href=view.php?ID=?php echo 
 $_SESSION['fullRestaurantList']['ID']??php echo 
 htmlspecialchars(stripslashes($_SESSION['fullRestaurantList'][$i]['name'])); 
 ?

What's the query?

I find (I use PostgreSQL rather than the mySQL that many on this list use) that
unless you explicitly ask for a field called ID (using  SELECT ID ... ) you
get a returned field in lower case
So
$resource = pg_query(SELECT ID, Foo FROM MyTable WHERE Foo='Bar');
$data = pg_fetch_all($resource)

gives me an array $data of rows like
$data[0]['id'] = '1'
$data[0]['foo'] = 'Bar'

To make sure $data[] has fields named ID and Foo I would have to do

$resource = pg_query(SELECT ID AS \ID\, Foo AS \Foo\ FROM MyTable WHERE
Foo='Bar');


-- 
Peter Ford  phone: 01580 89
Developer   fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Undefined index:

2007-06-16 Thread Al

There is obviously something else wrong.  That's the purpose of isset();

Comment out your line and see what happens.

I'd guess the real problem is later in your code when you are trying to do 
something with $HTTP_COOKIE_VARS[LoggedIn] even though your isset() test said 
it didn't exist.


WeberSites LTD wrote:
I'm using this code to check if a cookie has a value : 
 
If(!IsSet($HTTP_COOKIE_VARS[LoggedIn])) 
 
 
In case that this cookie is not set, how can i avoid the 
Undefined index: line in the error log?
 
berber




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: undefined index and php

2005-11-10 Thread Mark Rees
 I tried this to set the value...

 if (!isset($_POST['heading'])) {
 $_POST ['heading'] = ;
 }

 because the following line give the notice 'undefined index'  BEFORE  the
 submit button has been pressed..

 ? $heading_insert= stripslashes($_POST['heading']);?


What everyone else said, but also:

It's not good practice (in fact I don't even know if it's possible) to
modify the contents $_POST programmatically. It contains, as you no doubt
know, all of the variables POSTed to the script, generally by the submission
of a form with method=POST.

It would be better for you to assign the contents of $_POST to local
variables.  Firstly, you will be able to do any necessary checks and
modifications (length, variable type, presence of illegal characters and so
on) at the point when you create the variable. This will save you time if
you need to use the value multiple times on the same page.

example:

 $heading='';
 if (isset($_POST['heading'])) {
 $heading=$_POST ['heading'];
 }

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: undefined index and php

2005-11-10 Thread Richard Lynch
On Thu, November 10, 2005 8:38 am, Mark Rees wrote:
 It's not good practice (in fact I don't even know if it's possible) to

It's definitely possible in the sense that you can cram things in
there.

You can store your lunch in the trash can and pull it back out when
it's time to eat.

Neither of these is a particularly Good Idea (tm)

Any other place in your program, you expect $_POST to contain what the
browser/user/client/monkey sent as POST data.  Don't pollute that by
cramming your own data in there.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Undefined index ???

2004-06-09 Thread Torsten Roehr
Michael Jonsson [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 Hi

 Why do I get an error if the $_SESSION['user_status'] is NULL ???


 Script##
 session_start();
 echo $_SESSION['user_status'];


 #error##
 Notice: Undefined index: user_status in
 /var/www/itmdata/include/include.php on line 13

Did you really set it to null?:

$_SESSION['user_status'] = null; ?

Regards, Torsten

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Undefined index ???

2004-06-09 Thread Michael Jonsson
No, it's not set to NULL it just emty...
.M
Torsten Roehr wrote:
Michael Jonsson [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
Hi
Why do I get an error if the $_SESSION['user_status'] is NULL ???
Script##
session_start();
echo $_SESSION['user_status'];
#error##
Notice: Undefined index: user_status in
/var/www/itmdata/include/include.php on line 13

Did you really set it to null?:
$_SESSION['user_status'] = null; ?
Regards, Torsten
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: Undefined index ???

2004-06-09 Thread Torsten Roehr
Michael Jonsson [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 No, it's not set to NULL it just emty...

Empty means:

$_SESSION['user_status'] = '';
or
$_SESSION['user_status'] = 0;

Not setting it does NOT mean it's empty.

Torsten


 .M


 Torsten Roehr wrote:
  Michael Jonsson [EMAIL PROTECTED] wrote in message
  news:[EMAIL PROTECTED]
 
 Hi
 
 Why do I get an error if the $_SESSION['user_status'] is NULL ???
 
 
 Script##
 session_start();
 echo $_SESSION['user_status'];
 
 
 #error##
 Notice: Undefined index: user_status in
 /var/www/itmdata/include/include.php on line 13
 
 
  Did you really set it to null?:
 
  $_SESSION['user_status'] = null; ?
 
  Regards, Torsten

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Undefined index ???

2004-06-09 Thread Michael Jonsson
No, it's not set to NULL it's just emty...
.M
Torsten Roehr wrote:
Michael Jonsson [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
Hi
Why do I get an error if the $_SESSION['user_status'] is NULL ???
Script##
session_start();
echo $_SESSION['user_status'];
#error##
Notice: Undefined index: user_status in
/var/www/itmdata/include/include.php on line 13

Did you really set it to null?:
$_SESSION['user_status'] = null; ?
Regards, Torsten
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: Undefined index ????

2004-06-09 Thread Justin Patrin
Michael Jonsson wrote:
Hi
Why do I get an error if the $_SESSION['user_status'] is emty (it's not 
set to anything) ???
in my redhat 9 it did mork, but when I moved to Fedora Core 2 it's not 
working...

Script##
session_start();
echo $_SESSION['user_status'];
#error##
Notice: Undefined index: user_status in 
/var/www/itmdata/include/include.php on line 13


Regards
Micke
This is a notice. Try setting your error level to E_ALL  ~E_NOTICE or 
using isset() before you try to use the variable.

--
paperCrane Justin Patrin
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: Undefined Index - is this how you declare get post?

2003-10-29 Thread Jon Kriek
settype(), isset(), and empty() checks will all bypass this, but there is no
need to have error reporting set that high ...

error_reporting(2047);

-- 
Jon Kriek
http://phpfreaks.com

Terence [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 Hi List,

 Since I started using error_reporting(E_ALL), I havent found (in my
opinion)
 a good way to declare GET and POST variables when getting them from a form
 or querystring. I have searched google and the docs for several hours now
 without much luck.

 ?php
 error_reporting(E_ALL);
 // This line stops the error reporting, else I get - Notice: Undefined
 index: i in.
 $HTTP_GET_VARS[i]=;

 if ($HTTP_GET_VARS[i] == ) {
  include(myfile.php);
 }
 ?

 Is there a better way?
 I have tried var $i (only for classes I've discovered)
 settype($i, integer)

 Thanks in advance.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Undefined index:

2002-10-02 Thread Erwin

Voisine wrote:
 Hi,

 I'm learning php from a book but because of global off I have have
 several Undefined index message! I don't want to change the default
 setting in my php.ini because I want to learn the good way.
 What I'm doing wrong?

 Undefined index: categorie
 if ($_POST['categorie'] == New) {

You're not doing anything wrong. The problem here is that error_reporting
has notices on. The $_POST['categorie'] is not defined.
Change the error_reporting to excluse ERR_NOTICE, or use:

if ( isset( $_POST['categorie'] )  $_POST['categorie'] == 'New' ) }
// Your code here
}

HTH
Erwin




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Re: Undefined index, Undefined variable, Undefined constant....

2002-09-06 Thread Erwin

Jens Winberg wrote:
 I'm having trouble with the newest version of PHP (4.2.2).
 For example in a page I'm using the following code:
 if ($_GET['action'] == logout) {
//do something
 }

 But I'm getting an error message that says:
 ...log_message reports: PHP Notice:  Undefined index:  action in

 Ealier (other versions of PHP) I have succesfully used the above
 code, but do I now have to rewrite the code like this:
 if (isset($_GET['action']) AND $_GET['action'] == logout) {
//do something
 }

 Or am I totally wrong?
 This was just one example when I'm getting the message Undefined
 index or  Undefined variable etc. A lot of code which has
 previously worked is now giving me loads of headache since I have to
 rewrite everything.

Heh, that can be solved by setting the error_reporting in the php.ini to
E_ALL  ~E_NOTICE
They can also be disabled by putting the line error_reporting( E_ALL 
~E_NOTICE ) at the first (second, after the ?php) line in your code.

HTH Erwin



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Re: Undefined Index

2002-08-02 Thread Lars Olsson

Hi!

JüRgen wrote:
 It's me again, i don't mean to be a bugger, but i really like to learn as
 much as possible, that's why i ask (or will ask so many questions).
 
 Consider the following (i shortened this a lot, but it will do the trick)
 
 $op = $_GET['op'];
 switch ( $op )
 {
  case admin:
   DoLogin();
   break;
 
  default:
   ShowHomepage();
   break;
 }
 
 PHP shoots a Notice Message telling me that there is an undefined index
 Undefined index: act in g:\apache_web\intern\looney\index.php on line 177

You get this error message whenever $_GET doesn't contain anything.

 This accects the code shown above.
 
 Ok, am i correct in assuming that it pops this message because $op is not
 defined as anything yet?
 
 If so,should i always just do this
 
 $_POST['op'] = '';
 $op = $_GET['op'];
 switch ( $op )
 {
 //Code here
 }
 
 Or would it be better and more space efficient to do this
 $op = isset($_GET['op']);
 switch ( $op )
 {
 //Code here
 }
 Cause if i do that the Notice Message dissapears for some reason i yet fail
 to grab.

This doesn't work since the result of isset($_GET['op']) is either true 
or false, not a string value. You need to write it like this:

if (isset($_GET['op']) {
   $op = $_GET['op'];

   switch ($op)
   {
 //Code here
   }
}

 I would really appreciate if somebody could explain to me why the Notice
 dissapears when using isset(), and also what is the best method to use
 rather then the two shown above?
 How do you guysgirls handle this?
 
 Thanks a lot in advance for your time and patience!
 
 Best regards from Vienna,
 Jürgen
 
 
 

Hope this helps!

/lasso ([EMAIL PROTECTED])


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Re: Undefined Index

2002-08-02 Thread lallous

do this:

$op = isset($_GET['op'])  !empty($_GET['op']) ? $_GET['op'] : '';


JüRgen [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 It's me again, i don't mean to be a bugger, but i really like to learn as
 much as possible, that's why i ask (or will ask so many questions).

 Consider the following (i shortened this a lot, but it will do the trick)

 $op = $_GET['op'];
 switch ( $op )
 {
  case admin:
   DoLogin();
   break;

  default:
   ShowHomepage();
   break;
 }

 PHP shoots a Notice Message telling me that there is an undefined index
 Undefined index: act in g:\apache_web\intern\looney\index.php on line 177

 This accects the code shown above.

 Ok, am i correct in assuming that it pops this message because $op is not
 defined as anything yet?

 If so,should i always just do this

 $_POST['op'] = '';
 $op = $_GET['op'];
 switch ( $op )
 {
 //Code here
 }

 Or would it be better and more space efficient to do this
 $op = isset($_GET['op']);
 switch ( $op )
 {
 //Code here
 }
 Cause if i do that the Notice Message dissapears for some reason i yet
fail
 to grab.
 I would really appreciate if somebody could explain to me why the Notice
 dissapears when using isset(), and also what is the best method to use
 rather then the two shown above?
 How do you guysgirls handle this?

 Thanks a lot in advance for your time and patience!

 Best regards from Vienna,
 Jürgen






-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php