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
Post a Comment