PHP Login System with Admin Features

Would you like to react to this message? Create an account in a few clicks or log in to continue.
PHP Login System with Admin Features

This forum was created to talk about the PHP Login System with admin features created by jpmaster77 on evolt's website


    Adding new option fields Part 2

    Fred-Eric
    Fred-Eric


    Number of posts : 63
    Registration date : 2007-05-13

    Adding new option fields Part 2 Empty Adding new option fields Part 2

    Post  Fred-Eric Wed Feb 25, 2009 11:39 pm

    Now that we have modified the registration form with new option field country, it's time to edit userinfo.php and useredit.php.



    userinfo.php
    Open the file userinfo.php for editing, and add this code.
    we loop throught the countryArray() that we have created in the part 1 of this how-to.
    we asign $key and $value and check if there a match with requested user infos.
    Code:

    /* Country */
    foreach (countryArray() as $key => $value) if($req_user_info['country'] == $key) $country = $value;
    echo "<b>Country:</b> ".$country."<br>";

    useredit.php
    Open the file useredit.php for editing, and add this code.
    Almost as previous, but we loop each value in array and assign selected if match form value
    or request user info.
    Code:

    <tr>
    <td>Country:</td><td><select size="1" name="country">
    <option value=""></option>
    <?

    foreach (countryArray() as $key => $value) {
    if($form->value("country") == $key || $session->userinfo['country'] == $key) $selected = "selected";
    print '<option value="'.$key.'" ' . $selected . '>' . $value . '</option>';
    $selected = '';
    }

    ?>
    </select></td>
    <td><? echo $form->error("country"); ?></td>
    </tr>


    process.php
    just add $_POST['country'] argument to the $session->editaccount() class.
    Code:

    /**
    * procEditAccount - Attempts to edit the user's account
    * information, including the password, which must be verified
    * before a change is made.
    */
    function procEditAccount(){
    global $session, $form;
    /* Account edit attempt */
    $retval = $session->editAccount($_POST['curpass'], $_POST['newpass'], $_POST['email'],  $_POST['firstname'], $_POST['country']);

    /* Account edit successful */
    if($retval){
    $_SESSION['useredit'] = true;
    header("Location: ".$session->referrer);
    }
    /* Error found with form */
    else{
    $_SESSION['value_array'] = $_POST;
    $_SESSION['error_array'] = $form->getErrorArray();
    header("Location: ".$session->referrer);
    }
    }


    session.php
    Add $subcountry argument to the editAccount() function.
    Code:

    function editAccount($subcurpass, $subnewpass, $subemail, $subfirstname, $subcountry){

    ...

    Check for empty option seletion.
    Code:

    /*Country error checking */
    $field = "country"; 
    if($subcountry == '') $form->setError($field, "* country not entered"); 

    ...

    if no erro occured update the batabase
    Code:

    /* Change Country */
    if($subcountry) $database->updateUserField($this->username,"country",$subcountry);


    That's it your done.


    Last edited by Fred-Eric on Sat Mar 14, 2009 7:52 pm; edited 2 times in total

      Current date/time is Sun May 19, 2024 9:08 am