You are here: Re: undefined index and php « PHP « IT news, forums, messages
Re: undefined index and php

Posted by "Mark Rees" on 11/10/05 16:38

> 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'];
}

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация