notice undefinded variable

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
amirbwb
Forum Commoner
Posts: 89
Joined: Sat Oct 30, 2010 6:10 pm

notice undefinded variable

Post by amirbwb »

Hello, I am annoyed from this error !!!
Notice: undefined variable ...

I am creating a registration form with more than 10 fields and checkbox !!

I know that this error comes form the requirement of the isset() function but I can't support this anymore!!!!:@:@

for example:

Code: Select all

<form>
<input name="test" type="text" value="<?php echo $_POST['test'];?>">
</form>
I think if I want to do the isset condition each time it will take lot of time .. and the code will be more complicated when you look at it ...

I also tried to do this with a function wich I called it value($variable){if(isset($variable){echo $variable;})} but still not working ...

is there any way to disable this error, I am creating this site on my localhost, in case I disabled this on my localhost, may I find problems when I upload it to a paid domain ?? if yes what to do ?? Can I change php.ini inside a paid domain ??

thank you, and please don't convince me to do the isset condition
genix2011
Forum Commoner
Posts: 74
Joined: Tue Aug 02, 2011 4:00 pm

Re: notice undefinded variable

Post by genix2011 »

Hi,

write a getPost function, that does the checking automatically.

Example:

Code: Select all

<?php
function getPost($var){
     if(isset($_POST[$var])) return $_POST[$var];
     return "";
}

echo '<input name="test" type="text" value="' . getPost('test') . '">';
?>
You could also tell PHP to just show Errors by calling on top error_reporting(E_ERROR);, but I would strongly recommend the first method.

Greets.
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Re: notice undefinded variable

Post by flying_circus »

amirbwb wrote:I think if I want to do the isset condition each time it will take lot of time .. and the code will be more complicated when you look at it ...
amirbwb wrote:is there any way to disable this error
amirbwb wrote:please don't convince me to do the isset condition
You know, sometimes, you just have to have a little pride in your work...

Take the advice I gave you in this thread and the implementation advice given above, and create a solution in which you find to be elegant. Suppressing or Disabling errors is never the correct answer, it tells us that you are willing to put in only the minimum amount of effort required.

If programming were easy, everyone would do it.
Post Reply