supress errors at the page level? Undefined index errors.

This is a discussion on supress errors at the page level? Undefined index errors. within the PHP Language forums, part of the PHP Programming Forums category; I'm creating a simple reply form, and if a form item isn't answered I get an error: "...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-07-2003
LRW
 
Posts: n/a
Default supress errors at the page level? Undefined index errors.

I'm creating a simple reply form, and if a form item isn't answered I
get an error:
"Notice: Undefined index: rb_amntspent in
c:\inetpub\wwwroot\mackinaw\survey.php on line 36"
even if in the code I allow for an unselected item. (Code at the
bottom here.)
It works fine otherwise.

Now in the past I've made a change to php.ini to repress errors, but
for this project I don't have access to the php.ini.
Is there a way to supress errors on that page for that session?

Or, is there a way to just not get that error at all?

Thanks!
Liam

Here's a sample of the code that gets the form response. If an item is
selected, no error for that question, but if an item is not selected I
get the error above even though I still get a successful echo for the
"else" or "default" option which occurs if nothing is selected:

$rb_visited = $_POST["rb_visited"]; //Have you ever visited Mackinaw
City, Michigan?
if ($rb_visited == "1") {
$rb_visited_reply = "Yes";
} elseif ($rb_visited == "0") {
$rb_visited_reply = "No";
} else {
$rb_visited_reply = "You did not answer this question";
};

$rb_lastvisit = $_POST["rb_lastvisit"]; //When was your last visit to
Mackinaw ity?
switch ($rb_lastvisit) {
case "1":
$rb_lastvisit_reply = "Earlier this year (2003)";
break;
case "2":
$rb_lastvisit_reply = "Last year (2002)";
break;
case "3":
$rb_lastvisit_reply = "2 years ago (2001)";
break;
case "4":
$rb_lastvisit_reply = "3 years ago (2000)";
break;
case "5":
$rb_lastvisit_reply = "4 or more years ago (1999)";
break;
default:
$rb_lastvisit_reply = "You did not answer this uestion";
}
Reply With Quote
  #2 (permalink)  
Old 10-07-2003
Pedro
 
Posts: n/a
Default Re: supress errors at the page level? Undefined index errors.

LRW wrote:
> I'm creating a simple reply form, and if a form item isn't answered I
> get an error:
> "Notice: Undefined index: rb_amntspent in
> c:\inetpub\wwwroot\mackinaw\survey.php on line 36"
> even if in the code I allow for an unselected item. (Code at the
> bottom here.)


You can do it (at least) one of two ways (I prefer the first):

<?php
$arr['unset1'] = 1;
# $arr['unset2'] = 2;
$arr['unset3'] = 3;

// method 1
if (isset($arr['unset2']) {
$var = $arr['unset2'];
} else {
$var = 'impossible value';
}
// now test $var

// method 2
$var = @$arr['unset2'];
// now test $var; if $arr['unset2'] is undefined $var will be ''
?>


HTH

--
I have a spam filter working.
To mail me include "urkxvq" (with or without the quotes)
in the subject line, or your mail will be ruthlessly discarded.
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 06:27 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0