php-windows Digest 5 Jul 2010 08:42:35 -0000 Issue 3838

Topics (messages 30213 through 30215):

Re: Need help with HTML form errors
        30213 by: Sascha Meyer
        30214 by: nagendra prasad
        30215 by: Sascha Meyer

Administrivia:

To subscribe to the digest, e-mail:
        php-windows-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-windows-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-wind...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
Good Morning Nagendra,

Nagendra wrote:
> Sorry, I haven't mentioned in my earlier mail that the variables $filter
and
> $filterfield are global variables which I already defined.

I couldn't see this in your earlier mail but does the error occur inside a
PHP function? 
I would assume so and this could be due to not seeing the previously defined
variables 
because they are not declared as being in the global scope. Do you have code
like this 
in your routine handling the form output?

[CODE]
function form_handling ()
{
  global $filter, $filterfield;
  // the rest of the HTML form output
  <form action="index.php" method="post">
  <table class="bd" border="0" cellspacing="1" cellpadding="4"> <tr>
<td><b></b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp
;&nbsp;&nbsp;&nbsp;</td>
  <td><input type="text" name="filter" value="<?php echo $filter ?>"></td>
<td><input type="submit" name="action" value="Search"></td>
  ...
}
[/CODE]

Regards and keep us posted,

Sascha


--- End Message ---
--- Begin Message ---
So, What if I define the same global variable twice, will this solve the
issue?

--- End Message ---
--- Begin Message ---
Hi Nagendra,

Nagendra wrote:
> So, What if I define the same global variable twice, will this solve the
> issue?

No, this will most likely overwrite the values from the variables defined
outside of the routine.
I'll try to illustrate this a bit.

[CODE]
<?php
// WON'T WORK
// variables defined and set outside of the function
$filter = "123";
$filterfield = "ID";

function form_fill ()
{
  // both variables will be reinitialized with false and the values from the
outside scope will be discarded
  $filter;
  $filterfield;
}
[/CODE]

[CODE]
<?php
// WILL WORK
// variables defined and set outside of the function
$filter = "123";
$filterfield = "ID";

function form_fill ()
{
  // both variables are declared as being defined outside of the function
(global scope)
  global $filter, $filterfield;
}
[/CODE]

Did you do it like in the above example 2?

Regards, 

Sascha



--- End Message ---

Reply via email to