Re: [PHP] getting around the undefined index



At 11/27/2006 11:21 AM, Ross wrote:

$text = $_REQUEST['text_size'];
if ($text) {
echo $text;
}


I send the $text_size variable to the browser with lines like...

<a href="<? $_SERVER['PHP_SELF']; ?>?text_size=small" class="size1"
id="one">A</a>


When the page initially loads I get a undefined index error as it does not
exist but is there a way of wrapping in in a switch statement or funtion so
the variable is only used when $_REQUEST['text_size']; actually exists.


Using isset() you can determine whether or not a variable has been initialized (including an array element) before testing its value:
http://php.net/isset

By the way, I think you can simplify your href to:

<a href="?text_size=small" ...

By specifying just the querystring and not the file name, I believe it will always simply reload the current page with the querystring attached.

Regards,
Paul .



Relevant Pages

  • Re: 2 Qs re JS scripting
    ... This will guarantee that no web server will be involved and the test should ... The question is whether you want to deal with the queryString ... > in ASP or in the browser. ... This email account is my spam trap so I ...
    (microsoft.public.scripting.jscript)
  • Re: Fopen problems
    ... I mean to fopen (or whatelse function) a simple URL that should ... contain some stuff in querystring as when I try ... opening test.html directly on disk with fopen ... the browser for example? ...
    (comp.lang.php)
  • Re: Opening a webpage from a window form without showing the URL to the User
    ... Open the browser with page A alongwith username & password as ... Prev by Date: ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: DATA THROUGH QUERYSTRING
    ... "Steve" wrote in message ... Whatever you put in the QueryString will be displayed in the browser - that's just the way it works... ... Mark Rae ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: change text in browser address field
    ... When the page loads check whether the qs. ... is empty or not. ... querystring to a session variable and then redirect to the page mypage.aspx ...
    (microsoft.public.dotnet.framework.aspnet)