Page 1 of 1

notice undefinded variable

Posted: Wed Oct 26, 2011 3:30 pm
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

Re: notice undefinded variable

Posted: Wed Oct 26, 2011 3:52 pm
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.

Re: notice undefinded variable

Posted: Wed Oct 26, 2011 5:44 pm
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.