php - exception handling for undefined index error? -


the script below called when saving app's options page. options stored in array in $options.

i'm getting debug error "undefined index, id" on line comment below. ideas how can fix script?

        foreach ($options $value)          {             if( isset( $value['id'] ) && isset( $_request[$value['id']] ) )              {                 update_option( $value['id'], stripslashes($_request[$value['id']])  );              }             else             {                 update_option( $value['id'], ""); //error here             }         } 

your if{} segment precludes code in else{} segment working.

in other words:

in if block, ask: "does $value['id'] exist?"

if not, code executes else block, attempts reference non-existent variable.

you'll need set array key before can update it.

your update_option function should check see if variable exists, , set instead of updating it, if not.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -