Re: there must be better way to handle "Null" undefined variables

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> your general concept is correct...do it the right way
> 
> I am not adhering to MY way but why isn't my fix OK?
> 
> One variable fixed...fixing the rest would cause code gloat.

I think you mean Bloat.  Code doesn't take satisfaction from ruining
your day, it just feels like it does.

> I had a (flying) instrument instructor once who was famous for his teaching ability. 
> 
> If I made a mistake (and I did many times) he'd tell me why so I'd learn the concept. 
> 
> Thanks!
> 
> BTW is there anything you consider abrasive in my posts?
> 
> I am to the point to avoid post proliferation.
> 
> Here is only the pertinent code!
> 
> <form action="new_black_scholes.php" method="post">
>     <p>
>         Black Scholes Option Price Calculator:<br />
>         	temp website under Redhat Fedora 9 Linux:<br />
>         	the first 5 boxes require input(try 100. 100. .12 .1 365.):<br />
>     </p>
>     <p>
>         StockPrice (required):<br />
>         <input type="text" size="20" maxlength="40" name="StockPrice"
> 		value="<?php 
> 	if (IsSet($StockPrice)) 
> 	{
> 		echo $StockPrice; 
> 	}
> 	else 
> 	{
> 		echo " ";
> 	}
> 	?>" />
>     </p>
>     <p>
>         ExercisePrice (required):<br />
>         <input type="text" size="20" maxlength="40" name="ExercisePrice"
> 		value="<?php echo $ExercisePrice; ?>" />
> </p>

Your problem, as you have half realised, is the variables are not
initialised.  The simple answer is to make sure they are initialised.
Put something like this as the FIRST line of your script:

$StockPrice = $ExercisePrice = 0;

Include all of the numeric variables into this line. You can replace the
'0' with an empty string if you prefer.
Your conditional check for the 'Reset' and 'Submit' will set those
variables that it needs to, and the remainder will still have default
values.
 This will save you bloating the code with the 'IsSet' checking.

--
Niel Archer



-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux