FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Undefined variable
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Undefined variable [message #181242 is a reply to message #181239] Wed, 24 April 2013 09:53 Go to previous messageGo to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma:
Senior Member
On 4/23/2013 11:49 PM, Question Boy wrote:
> On Apr 23, 11:27 pm, Question Boy <question....@hotmail.com> wrote:
>> On Apr 23, 11:08 pm, Richard Yates <rich...@yatesguitar.com> wrote:
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>> On Tue, 23 Apr 2013 19:16:54 -0700 (PDT), Question Boy
>>
>>> <question....@hotmail.com> wrote:
>>>> I have an simple MySQL/PHP app and it appears to be functional but the
>>>> webmaster has informed me that it is throwing lots of errors. So he
>>>> showed me the log file and I am trying to remedy the issues, but have
>>>> a question.
>>
>>>> For instance, I have a block of code, such as:
>>
>>>> if ($iBookedBy=="Other") {
>>>> echo '<option selected value="Other">Other</option>';
>>>> } else {
>>>> echo '<option value="Other">Other</option>';
>>>> }
>>
>>>> which the log file reports as:
>>
>>>> PHP Notice: Undefined variable: iBookedBy
>>
>>>> Now I thought of trying:
>>
>>>> if (isset($iBookedBy)==TRUE && $iBookedBy=="Other") {
>>>> echo '<option selected value="Other">Other</option>';
>>>> } else {
>>>> echo '<option value="Other">Other</option>';
>>>> }
>>
>>>> but am not sure if the server will break because the variable isn't
>>>> set or if it will still throw an error because of the second,
>>>> original, part of the if statement? Is this a good way to handle the
>>>> problem, or am I going about this the wrong way and there is a better
>>>> method?
>>
>>>> Thank you for your help.
>>
>>>> QuestionBoy
>>
>>> 1. Yes, it will prevent the error notice.
>>
>>> 2. You do not need the ==TRUE. isset($iBookedBy) means the same
>>> isset($iBookedBy)==TRUE.
>>
>>> 3. Your asking the question suggests that you are trying to write code
>>> and run it directly on a production server rather than testing on a
>>> local server. The webmaster will be happier, and you will be much more
>>> productive, if you set up a local server like WAMP.
>>
>> Thank you for the reply.
>>
>> I was always under the impression that it was always beneficial to
>> explicitly put ==TRUE to avoid any arbitrary interpretations. I won't
>> waste my time anymore.
>>
>> My test server was not reporting any errors. I will look into which
>> setting has to be changed.
>>
>> Thank you once again.
>
> Even setting my test server to debug mode, I don't seem to get the
> errors reported on the production server?
>

Ensure your php.ini file on your development system has the following:

error_reporting = E_ALL // or E_ALL | E_STRICT
display_errors = on

The default for error_reporting is E_ALL & ~E_NOTICE, which will not
catch such problems (actually I'm surprised the production server has
E_NOTICE on - most don't).

display_errors will show the errors when they occur so you don't have to
go digging in the log file (it should definitely be off in a production
system).

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Rejecting Certain Non-ASCII Characters
Next Topic: determine a mysqli_result object
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Nov 24 19:24:46 GMT 2024

Total time taken to generate the page: 0.04147 seconds