Re: undefined index and php

From: Date: Thu, 10 Nov 2005 14:38:05 +0000
Subject: Re: undefined index and php
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-225513@lists.php.net to get a copy of this message
> 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']; }

« previous php.general (#225513) next »