supress errors at the page level? Undefined index errors.

Ask a Question related to PHP Development, Design and Development.

  1. #1

    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";
    }
    LRW Guest

  2. Similar Questions and Discussions

    1. Access undefined errors
      Hi everyone, I am new to Flex and I was trying to do a simple for loop and I keep getting this error: Error Access of undefined property. Here...
    2. CF4.5 Errors in logs and Unix 111 errors!
      :confused; Hi All, I have been getting a lot of Unix 111 errors and there are various errors in my coldfusion logs. I can't find any resources...
    3. CF stops sending page - no errors reported
      CFMX 6.1, windows2003 web edition Here are the first seven lines (of 570) of code: <SCRIPT LANGUAGE="JavaScript" > function...
    4. Errors in creating index in Acrobat 5 for Windows
      OK, to answer the previous 2 postings: - The files are text, not scans or outlines - They are in English - F is unusual for a drive letter, but...
    5. Page Not Found errors.
      Hi everyone, I have designed a couple of sites that use Secure pages to collect user information. NOW, what I'm finding (Quite a bit now), is...
  3. #2

    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.
    Pedro Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139