[PHP] Other Notice problem...
This is not the same question i asked yesterday. When i set error_reporting = E_ALL and display_errors = On in my php.ini, i get the next message: Notice: Undefined variable: varname in . How can i fix this problem without setting error_reporting = E_ALL ~E_NOTICE and/or display_errors = Off, or what way do you think is the best to resolve this problem? Thanks, RB _ Charla con tus amigos en línea mediante MSN Messenger: http://messenger.microsoft.com/es -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Other Notice problem...
This usually means that you're using a variable without having initialized it. For example $a = $b + 1; will give you that warning if no value is assigned to $b prior to this line. It's PHP's way of telling you that you might be doing something wrong. Perhaps if you post some of your code we can help better? Marco - php|architect -- The Monthly Magazine For PHP Professionals Come visit us on the web at http://www.phparch.com! On Fri, 2002-11-08 at 10:31, R B wrote: This is not the same question i asked yesterday. When i set error_reporting = E_ALL and display_errors = On in my php.ini, i get the next message: Notice: Undefined variable: varname in . How can i fix this problem without setting error_reporting = E_ALL ~E_NOTICE and/or display_errors = Off, or what way do you think is the best to resolve this problem? Thanks, RB _ Charla con tus amigos en línea mediante MSN Messenger: http://messenger.microsoft.com/es -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Other Notice problem...
At 16:31 08.11.2002, R B spoke out and said: [snip] This is not the same question i asked yesterday. When i set error_reporting = E_ALL and display_errors = On in my php.ini, i get the next message: Notice: Undefined variable: varname in . How can i fix this problem without setting error_reporting = E_ALL ~E_NOTICE and/or display_errors = Off, or what way do you think is the best to resolve this problem? [snip] But it's the same answer ;-) If you want to be completely warning-and-notice-free, you need to define the variable before accessing it: // this will give a notice echo $undefined_var; // and this won't $define_var = 'some data, or simply put null here'; echo $defined_var; The same holds true for array indices: $test_array = array('One', 'Two', 'Three'); // this will give a notice echo $test_array[3]; // and this won't echo $test_array[2]; // and this won't as well if (array_key_exists(3)) echo $test_array[3]; Get the idea? IMHO it's complete overkill with PHP to predefine variables since they're auto-initialized with NULL when used first. These notices are only for the development cycle, to aid us in spotting a problem where you expect some data to be there, but it aint because the variable name has been mistyped... -- O Ernest E. Vogelsinger (\) ICQ #13394035 ^ http://www.vogelsinger.at/
Re: [PHP] Other Notice problem...
My code is: ?php some code. if ($status == ADD) { some code ... ... ... } ? The message is: Notice: Undefined variable: status in I'm going to explain how my script work. I have an php page (addProduct.php) with an input form. I have 2 buttons (add and cancel) and a hidden control with name=status. If i press the add button, the page submit the form data to the same page (form action=addProduct.php) with status hidden control name set to ADD, so the if statement its true only if i press the add button. I see the message when i call the page to add the data not when i submit the data. How can i fix the problem? or there is another best way to do this? From: Marco Tabini [EMAIL PROTECTED] To: R B [EMAIL PROTECTED] CC: [EMAIL PROTECTED] Subject: Re: [PHP] Other Notice problem... Date: 08 Nov 2002 10:25:46 -0500 This usually means that you're using a variable without having initialized it. For example $a = $b + 1; will give you that warning if no value is assigned to $b prior to this line. It's PHP's way of telling you that you might be doing something wrong. Perhaps if you post some of your code we can help better? Marco - php|architect -- The Monthly Magazine For PHP Professionals Come visit us on the web at http://www.phparch.com! On Fri, 2002-11-08 at 10:31, R B wrote: This is not the same question i asked yesterday. When i set error_reporting = E_ALL and display_errors = On in my php.ini, i get the next message: Notice: Undefined variable: varname in . How can i fix this problem without setting error_reporting = E_ALL ~E_NOTICE and/or display_errors = Off, or what way do you think is the best to resolve this problem? Thanks, RB _ Charla con tus amigos en línea mediante MSN Messenger: http://messenger.microsoft.com/es -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php _ MSN. Más Útil Cada Día http://www.msn.es/intmap/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Other Notice problem...
Try if (isset ($status) $status == 'ADD') instead... this should take care of the error--IF you're sure that the fact that the $status variable is not set at that point is ok. Marco - php|architect -- The Monthly Magazine For PHP Professionals Come visit us on the web at http://www.phparch.com! On Fri, 2002-11-08 at 11:04, R B wrote: My code is: ?php some code. if ($status == ADD) { some code ... ... ... } ? The message is: Notice: Undefined variable: status in I'm going to explain how my script work. I have an php page (addProduct.php) with an input form. I have 2 buttons (add and cancel) and a hidden control with name=status. If i press the add button, the page submit the form data to the same page (form action=addProduct.php) with status hidden control name set to ADD, so the if statement its true only if i press the add button. I see the message when i call the page to add the data not when i submit the data. How can i fix the problem? or there is another best way to do this? From: Marco Tabini [EMAIL PROTECTED] To: R B [EMAIL PROTECTED] CC: [EMAIL PROTECTED] Subject: Re: [PHP] Other Notice problem... Date: 08 Nov 2002 10:25:46 -0500 This usually means that you're using a variable without having initialized it. For example $a = $b + 1; will give you that warning if no value is assigned to $b prior to this line. It's PHP's way of telling you that you might be doing something wrong. Perhaps if you post some of your code we can help better? Marco - php|architect -- The Monthly Magazine For PHP Professionals Come visit us on the web at http://www.phparch.com! On Fri, 2002-11-08 at 10:31, R B wrote: This is not the same question i asked yesterday. When i set error_reporting = E_ALL and display_errors = On in my php.ini, i get the next message: Notice: Undefined variable: varname in . How can i fix this problem without setting error_reporting = E_ALL ~E_NOTICE and/or display_errors = Off, or what way do you think is the best to resolve this problem? Thanks, RB _ Charla con tus amigos en línea mediante MSN Messenger: http://messenger.microsoft.com/es -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php _ MSN. Más Útil Cada Día http://www.msn.es/intmap/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Other Notice problem...
At 17:04 08.11.2002, R B spoke out and said: [snip] I'm going to explain how my script work. I have an php page (addProduct.php) with an input form. I have 2 buttons (add and cancel) and a hidden control with name=status. If i press the add button, the page submit the form data to the same page (form action=addProduct.php) with status hidden control name set to ADD, so the if statement its true only if i press the add button. I see the message when i call the page to add the data not when i submit the data. [snip] Ahhh your $status variable should be a form variable? Well, as pointed out many times the last days, register_globals is OFF by default since PHP v.4.something. Either turn register_globals on in your PHP.ini (bad and deprecated, read the security bulletins), or you refer to the _POST array: if ($_POST['status'] == ADD) if the data is not set (the status control empty), you'll still get a notice about an undefined array index, so you might if (array_key_exists('status', $_POST)) { switch ($_POST['status']) { case 'ADD': break; default: echo 'Unsupported status!'; } } else echo 'No status sent!'; -- O Ernest E. Vogelsinger (\) ICQ #13394035 ^ http://www.vogelsinger.at/
Re: [PHP] Other Notice problem...
The array_key_exists or isset is a good solution. About your comment, i have the register_globals=on. I have 2 questions: 1.- What's the relation to have register_globals=off with this notice message? 2.- I read the security comment about register_globals=on in the php.ini, but i set to on because if i set to off, i can't pass GET variables to other page. how can you pass GET variables to other page without setting register_globals=on? From: Ernest E Vogelsinger [EMAIL PROTECTED] To: R B [EMAIL PROTECTED] CC: [EMAIL PROTECTED],[EMAIL PROTECTED] Subject: Re: [PHP] Other Notice problem... Date: Fri, 08 Nov 2002 17:14:30 +0100 At 17:04 08.11.2002, R B spoke out and said: [snip] I'm going to explain how my script work. I have an php page (addProduct.php) with an input form. I have 2 buttons (add and cancel) and a hidden control with name=status. If i press the add button, the page submit the form data to the same page (form action=addProduct.php) with status hidden control name set to ADD, so the if statement its true only if i press the add button. I see the message when i call the page to add the data not when i submit the data. [snip] Ahhh your $status variable should be a form variable? Well, as pointed out many times the last days, register_globals is OFF by default since PHP v.4.something. Either turn register_globals on in your PHP.ini (bad and deprecated, read the security bulletins), or you refer to the _POST array: if ($_POST['status'] == ADD) if the data is not set (the status control empty), you'll still get a notice about an undefined array index, so you might if (array_key_exists('status', $_POST)) { switch ($_POST['status']) { case 'ADD': break; default: echo 'Unsupported status!'; } } else echo 'No status sent!'; -- O Ernest E. Vogelsinger (\) ICQ #13394035 ^ http://www.vogelsinger.at/ _ MSN. Más Útil Cada Día http://www.msn.es/intmap/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Other Notice problem...
At 17:27 08.11.2002, R B spoke out and said: [snip] The array_key_exists or isset is a good solution. About your comment, i have the register_globals=on. I have 2 questions: 1.- What's the relation to have register_globals=off with this notice message? If register_globals is OFF, $status will simply not be set by PHP. You can always access it as $_POST['status'] or $_REQUEST['status']. 2.- I read the security comment about register_globals=on in the php.ini, but i set to on because if i set to off, i can't pass GET variables to other page. how can you pass GET variables to other page without setting register_globals=on? What do you mean by pass it on to other page? I'm afraid I don't get you. What are you trying to accomplish? -- O Ernest E. Vogelsinger (\) ICQ #13394035 ^ http://www.vogelsinger.at/
Re: [PHP] Other Notice problem...
About your comment 1: if i have register_globals=on, why $status is not be set by PHP? About your comment 2: if i have 2 pages: p01.php and p02.php, with p01.php code: ... ... a href=p02.php?pp=2link/a ... ... and p02.php code: ... ... echo $pp; ... ... If i have register_globals=off, then when i click the link, in p02.php page, the echo command display nothing. If i have register_globals=on, then the echo command displays the value buy this way is deprecated. How can i run the script without problems having register_globals=off? Thanks, RB From: Ernest E Vogelsinger [EMAIL PROTECTED] To: R B [EMAIL PROTECTED] CC: [EMAIL PROTECTED],[EMAIL PROTECTED] Subject: Re: [PHP] Other Notice problem... Date: Fri, 08 Nov 2002 17:31:25 +0100 At 17:27 08.11.2002, R B spoke out and said: [snip] The array_key_exists or isset is a good solution. About your comment, i have the register_globals=on. I have 2 questions: 1.- What's the relation to have register_globals=off with this notice message? If register_globals is OFF, $status will simply not be set by PHP. You can always access it as $_POST['status'] or $_REQUEST['status']. 2.- I read the security comment about register_globals=on in the php.ini, but i set to on because if i set to off, i can't pass GET variables to other page. how can you pass GET variables to other page without setting register_globals=on? What do you mean by pass it on to other page? I'm afraid I don't get you. What are you trying to accomplish? -- O Ernest E. Vogelsinger (\) ICQ #13394035 ^ http://www.vogelsinger.at/ _ Charla con tus amigos en línea mediante MSN Messenger: http://messenger.microsoft.com/es -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Other Notice problem...
On Friday, Nov 8, 2002, at 16:44 Europe/London, R B wrote: if i have 2 pages: p01.php and p02.php, with p01.php code: ... ... a href=p02.php?pp=2link/a ... ... and p02.php code: ... ... echo $pp; ... ... If i have register_globals=off, then when i click the link, in p02.php page, the echo command display nothing. If i have register_globals=on, then the echo command displays the value buy this way is deprecated. How can i run the script without problems having register_globals=off? p02.php code: ... ... echo $_GET['pp']; ... ... -- Stuart -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Other Notice problem...
And without using the $_GET[] array. From: Stuart [EMAIL PROTECTED] To: R B [EMAIL PROTECTED] CC: [EMAIL PROTECTED], [EMAIL PROTECTED], [EMAIL PROTECTED] Subject: Re: [PHP] Other Notice problem... Date: Fri, 8 Nov 2002 16:52:50 + On Friday, Nov 8, 2002, at 16:44 Europe/London, R B wrote: if i have 2 pages: p01.php and p02.php, with p01.php code: ... ... a href=p02.php?pp=2link/a ... ... and p02.php code: ... ... echo $pp; ... ... If i have register_globals=off, then when i click the link, in p02.php page, the echo command display nothing. If i have register_globals=on, then the echo command displays the value buy this way is deprecated. How can i run the script without problems having register_globals=off? p02.php code: ... ... echo $_GET['pp']; ... ... -- Stuart _ Charla con tus amigos en línea mediante MSN Messenger: http://messenger.microsoft.com/es -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Other Notice problem...
On Friday, Nov 8, 2002, at 16:56 Europe/London, R B wrote: And without using the $_GET[] array. Why don't you want to use the $_GET array? If you really don't want to use it you can use the extract function but if you're going to do that you might as well have register_globals on. -- Stuart p02.php code: ... ... echo $_GET['pp']; ... ... -- Stuart -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Other Notice problem...
At 17:44 08.11.2002, R B spoke out and said: [snip] About your comment 1: if i have register_globals=on, why $status is not be set by PHP? well _then_ we have 2 possibilities: 1) your form input field isn't named status but rather Status or STATUS - take care of the case here, PHP is case sensitive with variables and associative indices. 2) Your form simply submits _nothing_ in this field - check your JavaScript (perhaps it is disabled?) About your comment 2: if i have 2 pages: p01.php and p02.php, with p01.php code: ... a href=p02.php?pp=2link/a ... and p02.php code: ... echo $pp; If i have register_globals=off, then when i click the link, in p02.php page, the echo command display nothing. If i have register_globals=on, then the echo command displays the value buy this way is deprecated. How can i run the script without problems having register_globals=off? ?php $parms = null; foreach ($_GET as $p=$v) { if ($parms) $parms .= ''; $parms .= $p=.urlencode($v); } ? ... a href=p02.php??php=$parms? This will do what you want (untested, but should work) -- O Ernest E. Vogelsinger (\) ICQ #13394035 ^ http://www.vogelsinger.at/
Re: [PHP] Other Notice problem...
On Saturday 09 November 2002 00:52, Stuart wrote: How can i run the script without problems having register_globals=off? p02.php code: ... ... echo $_GET['pp']; ... ... Yes. And try reading the manual, or the archives. -- Jason Wong - Gremlins Associates - www.gremlins.com.hk Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * /* While money can't buy happiness, it certainly lets you choose your own form of misery. */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Other Notice problem...
On Saturday 09 November 2002 00:56, R B wrote: And without using the $_GET[] array. Probably by using black magic instead -- or maybe use $_REQUEST, but I don't think you want to use that either :) -- Jason Wong - Gremlins Associates - www.gremlins.com.hk Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * /* Auribus teneo lupum. [I hold a wolf by the ears.] [Boy, it *sounds* good. But what does it *mean*?] */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Other Notice problem...
Well, it's possible he's using an older version of PHP in which superglobals did not yet exist. Marco - php|architect -- The Monthly Magazine For PHP Professionals Come visit us on the web at http://www.phparch.com! On Fri, 2002-11-08 at 12:09, Jason Wong wrote: On Saturday 09 November 2002 00:56, R B wrote: And without using the $_GET[] array. Probably by using black magic instead -- or maybe use $_REQUEST, but I don't think you want to use that either :) -- Jason Wong - Gremlins Associates - www.gremlins.com.hk Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * /* Auribus teneo lupum. [I hold a wolf by the ears.] [Boy, it *sounds* good. But what does it *mean*?] */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Other Notice problem...
On Saturday 09 November 2002 01:02, Marco Tabini wrote: Well, it's possible he's using an older version of PHP in which superglobals did not yet exist. It looks to me as if he just wants to use plain $variable but with register_globals disabled that's just not possible. Unless you go through that extract($_POST) ritual, all of which is covered in the manual and archives. -- Jason Wong - Gremlins Associates - www.gremlins.com.hk Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * /* The biggest problem with communication is the illusion that it has occurred. */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Other Notice problem...
It's ok. I understand that i can't use plain variables with register_globals=on, but this is only for GET variables or to all variables? Thanks, RB From: Jason Wong [EMAIL PROTECTED] Reply-To: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Subject: Re: [PHP] Other Notice problem... Date: Sat, 9 Nov 2002 01:42:56 +0800 On Saturday 09 November 2002 01:02, Marco Tabini wrote: Well, it's possible he's using an older version of PHP in which superglobals did not yet exist. It looks to me as if he just wants to use plain $variable but with register_globals disabled that's just not possible. Unless you go through that extract($_POST) ritual, all of which is covered in the manual and archives. -- Jason Wong - Gremlins Associates - www.gremlins.com.hk Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * /* The biggest problem with communication is the illusion that it has occurred. */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php _ MSN Fotos: la forma más fácil de compartir e imprimir fotos. http://photos.msn.es/support/worldwide.aspx -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Other Notice problem...
On Friday, Nov 8, 2002, at 17:59 Europe/London, R B wrote: It's ok. I understand that i can't use plain variables with register_globals=on, but this is only for GET variables or to all variables? The value of register_globals only affects the CGI variables (get, post, server, cookies, etc). You can use other variables in the same way as you ever did. -- Stuart -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php