Re: Setting & displaying Variables [message #182873 is a reply to message #182868] |
Sun, 22 September 2013 21:58 |
Richard Damon
Messages: 58 Registered: August 2011
Karma:
|
Member |
|
|
On 9/22/13 4:47 PM, Twayne wrote:
> On 2013-09-21 4:47 PM, Richard Damon wrote:
>> On 9/21/13 4:20 PM, Twayne wrote:
>>> Hi,
>>>
>>> Obviously, the issue is around the comments var. It works, but it
>>> doesn't and I'm hoping someone can explain why.
>>>
>>> Both echo strlen($comments); and echo $comments; throw a Notice
>>> about an undefined variable. But the variable "comments" HAS to have
>>> been defined in order for the two echo statements to work!
>>> The variable 'comments' is also in SESSION data, which will also get
>>> the same Notice of an undefined variable.
>>>
>>> What the heck am I missing? Why do I get the undefined var in those two
>>> statements?
>>>
>>> ===================
>>> <code>
>>> echo strlen($_POST["comments"])."<br />"; //WORKS
>>>
>>> $commments = $_POST["comments"]; // WORKS but not needed; done elsewhere
>>> too.
>>>
>>> // echo strlen($comments); // GETS Notice: Undefined variable: comments
>>> in C:\xampp\htdocs... and nothing displays.
>>>
>>> echo $_POST["comments"]; // WORKS
>>> //echo $comments; // GETS Notice: Undefined variable: comments in C
>>> ... and nothing displays.
>>>
>>> </code>
>>> ===================
> ...
>>
>> As others have commented on, not showing us the full code makes it very
>> hard to help. The error message you are quoting says that the variable
>> does NOT at that point have a value assigned to it.
>
> No, and I doubt anyone would go thru 500 lines of code even if I were
> allowed to post it.
> That said, the snippet above is ONE snippet of consecutive code lines;
> they are not simply gathered into one place; That's the precise order
> they occur in.
>
The first step of reporting such a problem is to reduce your problem to
a simple case that demonstrates the issue. It seemed that you had done
that, but never gave us the code.
For example, the above code is NOT a piece of code that demonstrates the
problem, since the line reported as generating the NOTICE has been
commented out.
As pointed out else-thread, the problem was a typo, but since you
clearly weren't showing all thoe code (from things like the comment of
being done elsewhere), we could not tell if that same typo was done THERE.
|
|
|