[PHP] undefined index and php
Before someone advises me to 'google' my question. I have and can't find a PHP.net example either. I have turned off registered globals and am updating my scripts so they work but I keep getting an undefined index problem using $_POST 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']);? R. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] undefined index and php
Ross wrote: because the following line give the notice 'undefined index' BEFORE the submit button has been pressed.. ? $heading_insert= stripslashes($_POST['heading']);? That's because before the submit button has been pressed, $_POST is empty and so 'heading' is indeed an undefined index. Try: $heading_insert = isset( $_POST['heading'] ) ? stripslashes( $_POST['heading'] ) : ''; By the way, while you're switching register_globals off, it might be a good idea to also switch off magic_quotes_gpc (the reason you need stripslashes() above) and short_open_tag (judging by your use of the non-portable ? open tag rather than ?php). Jasper -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] undefined index and php
I have never really used this abreviated format before why the question mark and the colon? What is the long hang eqivalent. I turned magic quotes off too. thanks. R. - Original Message - From: Jasper Bryant-Greene [EMAIL PROTECTED] To: Ross [EMAIL PROTECTED] Cc: php-general@lists.php.net Sent: Thursday, November 10, 2005 12:19 PM Subject: Re: [PHP] undefined index and php Ross wrote: because the following line give the notice 'undefined index' BEFORE the submit button has been pressed.. ? $heading_insert= stripslashes($_POST['heading']);? That's because before the submit button has been pressed, $_POST is empty and so 'heading' is indeed an undefined index. Try: $heading_insert = isset( $_POST['heading'] ) ? stripslashes( $_POST['heading'] ) : ''; By the way, while you're switching register_globals off, it might be a good idea to also switch off magic_quotes_gpc (the reason you need stripslashes() above) and short_open_tag (judging by your use of the non-portable ? open tag rather than ?php). Jasper -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] undefined index and php
The question mark and colon is the equivalent for the iif function. It's a short hand for if/else. You start with the expression, and if true, do what's after the question mark and if false, after the column. Robbert -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Thursday, November 10, 2005 4:58 AM To: php-general@lists.php.net Subject: Re: [PHP] undefined index and php I have never really used this abreviated format before why the question mark and the colon? What is the long hang eqivalent. I turned magic quotes off too. thanks. R. - Original Message - From: Jasper Bryant-Greene [EMAIL PROTECTED] To: Ross [EMAIL PROTECTED] Cc: php-general@lists.php.net Sent: Thursday, November 10, 2005 12:19 PM Subject: Re: [PHP] undefined index and php Ross wrote: because the following line give the notice 'undefined index' BEFORE the submit button has been pressed.. ? $heading_insert= stripslashes($_POST['heading']);? That's because before the submit button has been pressed, $_POST is empty and so 'heading' is indeed an undefined index. Try: $heading_insert = isset( $_POST['heading'] ) ? stripslashes( $_POST['heading'] ) : ''; By the way, while you're switching register_globals off, it might be a good idea to also switch off magic_quotes_gpc (the reason you need stripslashes() above) and short_open_tag (judging by your use of the non-portable ? open tag rather than ?php). Jasper -- 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] undefined index and php
Robbert van Andel wrote: The question mark and colon is the equivalent for the iif function. It's a 'if () ...' is not a function it's a language construct. they are different :-) for instance 'echo' is also a language construct which is why it does not require brackets e.g. $space = ' '; echo hello,$space,world; short hand for if/else. You start with the expression, and if true, do what's after the question mark and if false, after the column. Robbert -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Thursday, November 10, 2005 4:58 AM To: php-general@lists.php.net Subject: Re: [PHP] undefined index and php I have never really used this abreviated format before why the question mark and the colon? What is the long hang eqivalent. I turned magic quotes off too. thanks. R. - Original Message - From: Jasper Bryant-Greene [EMAIL PROTECTED] To: Ross [EMAIL PROTECTED] Cc: php-general@lists.php.net Sent: Thursday, November 10, 2005 12:19 PM Subject: Re: [PHP] undefined index and php Ross wrote: because the following line give the notice 'undefined index' BEFORE the submit button has been pressed.. ? $heading_insert= stripslashes($_POST['heading']);? That's because before the submit button has been pressed, $_POST is empty and so 'heading' is indeed an undefined index. Try: $heading_insert = isset( $_POST['heading'] ) ? stripslashes( $_POST['heading'] ) : ''; By the way, while you're switching register_globals off, it might be a good idea to also switch off magic_quotes_gpc (the reason you need stripslashes() above) and short_open_tag (judging by your use of the non-portable ? open tag rather than ?php). Jasper -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] undefined index and php
Hello. [EMAIL PROTECTED] wrote: why the question mark and the colon? What is the long hang eqivalent. That's the Ternary operator. Whether you want to get further information, go to: http://php.net/manual/en/language.operators.comparison.php Regards. -- Gustavo Narea. PHP Documentation - Spanish Translation Team. Valencia, Venezuela. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] undefined index and php
On Thu, November 10, 2005 5:54 am, Ross wrote: Before someone advises me to 'google' my question. I have and can't find a PHP.net example either. I have turned off registered globals and am updating my scripts so they work but I keep getting an undefined index problem using $_POST 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']);? This bit of code is getting run BEFORE the submit button has been pressed. In that case, $_POST itself is not defined, much less $_POST['heading'] You really shouldn't be stuffing values into $_POST. Think of it as a read-only variable that the browser sends TO you. Here are some options: OPTION 1: ?php $heading_insert = ''; if (isset($_POST['heading'])){ $heading_insert = stripslashes($_POST['heading']); } ? OPTION 2: ?php $heading_insert = isset($_POST['heading']) ? stripslashes($_POST['heading']) : ''; ? Some people think the ternary operator is confusing or obscure or whatever. Others think it's a perfectly natural operator. YMMV -- 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