Menu

"work" index not defined

Help
2010-09-14
2012-06-07
  • Greg Jewett

    Greg Jewett - 2010-09-14

    I am playing around with addressbook, and when looking at the logs, I noticed
    the following error:

    PHP Notice: Undefined index: work in
    /var/www/html/addressbook/include/address.class.php on line 175, referer: htt
    ps://addressbook.iat.utexas.edu/edit.php

    I looked in the source code, I could not find anything wrong. I am not a
    hardened PHP programmer, but found the following code that it seems to not
    like:

    //

    // Phone order home->mobile->work->phone2

    //

    public function getPhones() {

    $phones = array();

    if($this->address != "") $phones = $this->address;

    if($this->address != "") $phones = $this->address;

    if($this->address != "") $phones = $this->address;

    if($this->address != "") $phones = $this->address;

    return $phones;

    }

    I could not see any errors, code above these lines define "work", so I am not
    sure what it is complaining about. The only thing odd I saw was a possible
    bug, that where phone2 will be set to the work number, not phone2.

    So, first, why is this error popping up. Secondly, the work phone field is not
    being shown or saved. Is this related? You enter data into the work phone
    field, hit "update" and no changes are saved to the work phone field.

    HELP!?

     
  • Greg Jewett

    Greg Jewett - 2010-09-14

    NOTE: Found the issue.

    The problem is not in the PHP code, but the addressbook.sql file. The field
    called "work" was capitalized, and mySQL is case sensitive, so it was throwing
    errors. I made it lowercase, and the errors went away.

     
  • Greg Jewett

    Greg Jewett - 2010-09-14

    Curious code confusion still stands however. In the code below, as mentioned
    above.. should the

    last line read: if($this->address != "") $phones = $this->address;

    NOT: if($this->address != "") $phones = $this->address;

    Typo or on purpose?

    //

    // Phone order home->mobile->work->phone2

    //

    public function getPhones() {

    $phones = array();

    if($this->address != "") $phones = $this->address;

    if($this->address != "") $phones = $this->address;

    if($this->address != "") $phones = $this->address;

    if($this->address != "") $phones = $this->address;

    return $phones;

    }

     
  • chatelao

    chatelao - 2010-09-14

    Hi, which version of the addressbook are you using? - Regards O.

     

Log in to post a comment.