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 radio buttons

    Share
    avatar
    Fred-Eric

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

    Adding radio buttons

    Post  Fred-Eric on Thu Feb 26, 2009 12:22 am

    Adding radio box for registration

    Part 1 : Registration

    SQL
    Code:

    ALTER TABLE `users` ADD `gender` VARCHAR( 6 ) NOT NULL ;

    register.php
    Code:

    <tr>
    <td>Gender:</td>
    <td>
    <input type="radio" value="Female" name="gender" <? if($form->value("gender") == 'Female') print 'checked="checked"'; ?> />Female
    <input type="radio" value="Male" name="gender" <? if($form->value("gender") == 'Male') print 'checked="checked"'; ?> />Male
    </td>
    <td><? echo $form->error("gender"); ?></td>
    </tr>


    process.php
    Code:

    $retval = $session->editAccount($_POST['curpass'], $_POST['newpass'], $_POST['email'],  $_POST['firstname'], $_POST['country'], $_POST['gender']);


    session.php
    Code:

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


    session.php
    Code:

    /*Gender error checking */
    $field = "gender"; 
    if($subgender == '') $form->setError($field, "* gender not entered");


    session.php
    Code:

    /* Change gender */
    if($subgender) $database->updateUserField($this->username,"gender",$subgender);


    That's it your done...


    Part 2 : Editing account

    It's time to edit userinfo.php and useredit.php.

    userinfo.php
    Open the file userinfo.php for editing, and add this code.
    Code:

    /* gender */
    echo "<b>Gender:</b> ".$req_user_info['gender']."<br>";

    useredit.php
    Open the file useredit.php for editing, and add this code.
    Code:

    <tr>
    <td>Gender:</td>
    <td>
    <input type="radio" value="Female" name="gender" <? if($form->value("gender") == 'Female' || $session->userinfo['gender'] == 'Female') print 'checked="checked"'; ?> />Female
    <input type="radio" value="Male" name="gender" <? if($form->value("gender") == 'Male' || $session->userinfo['gender'] == 'Male') print 'checked="checked"'; ?> />Male
    </td>
    <td><? echo $form->error("gender"); ?></td>
    </tr>


    process.php
    just add $_POST['gender'] 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'], $_POST['gender');

    /* 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 $subgender argument to the editAccount() function.
    Code:

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

    ...

    Check for empty radio selection.
    Code:

    /*gender error checking */
    $field = "gender"; 
    if($subgender == '') $form->setError($field, "* gender not selected"); 

    ...

    if no erro occured update the batabase
    Code:

    /* Change Gender */
    if($subgender) $database->updateUserField($this->username,"gender",$subgender);


    That's it your done.

      Current date/time is Tue Sep 19, 2017 9:29 am