Re: undefined index and php

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> 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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux