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

Posted by "Richard Lynch" on 11/10/05 23:17

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

 

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

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