Re: getting around the undefined index
| From: | Paul Novitski | Date: | Mon, 27 Nov 2006 19:52:47 +0000 |
| Subject: | Re: getting around the undefined index | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-245195@lists.php.net to get a copy of this message | ||
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