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 1

    Share
    avatar
    Fred-Eric

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

    Adding new option fields Part 1

    Post  Fred-Eric on Wed Feb 25, 2009 9:50 pm

    Here I will explain how to add select and manage option box(dropdown menu).

    SQL part:
    Code:

    ALTER TABLE `users` ADD `country` VARCHAR( 2 ) NOT NULL ;

    We will hack the actual structure of that script by adding a new files to the hole directory structure add we will include it to the actual login system. We will add to session.php

    session.php
    Place this code just after the include of the database.php
    Code:

    include_once('function.php');


    function.php
    Create a new php file and name it function.php and place it into include filder.
    Open the new file function and add this function:
    Code:

    /* this function is part of function.php */
    function countryArray(){
    return array(
    'AF'=>'Afghanistan',
    'AL'=>'Albania',
    'DZ'=>'Algeria',
    'AS'=>'American Samoa',
    'AD'=>'Andorra',
    'AO'=>'Angola',
    'AI'=>'Anguilla',
    'AQ'=>'Antarctica',
    'AG'=>'Antigua And Barbuda',
    'AR'=>'Argentina',
    'AM'=>'Armenia',
    'AW'=>'Aruba',
    'AU'=>'Australia',
    'AT'=>'Austria',
    'AZ'=>'Azerbaijan',
    'BS'=>'Bahamas',
    'BH'=>'Bahrain',
    'BD'=>'Bangladesh',
    'BB'=>'Barbados',
    'BY'=>'Belarus',
    'BE'=>'Belgium',
    'BZ'=>'Belize',
    'BJ'=>'Benin',
    'BM'=>'Bermuda',
    'BT'=>'Bhutan',
    'BO'=>'Bolivia',
    'BA'=>'Bosnia And Herzegovina',
    'BW'=>'Botswana',
    'BV'=>'Bouvet Island',
    'BR'=>'Brazil',
    'IO'=>'British Indian Ocean Territory',
    'BN'=>'Brunei',
    'BG'=>'Bulgaria',
    'BF'=>'Burkina Faso',
    'BI'=>'Burundi',
    'KH'=>'Cambodia',
    'CM'=>'Cameroon',
    'CA'=>'Canada',
    'CV'=>'Cape Verde',
    'KY'=>'Cayman Islands',
    'CF'=>'Central African Republic',
    'TD'=>'Chad',
    'CL'=>'Chile',
    'CN'=>'China',
    'CX'=>'Christmas Island',
    'CC'=>'Cocos (Keeling) Islands',
    'CO'=>'Columbia',
    'KM'=>'Comoros',
    'CG'=>'Congo',
    'CK'=>'Cook Islands',
    'CR'=>'Costa Rica',
    'CI'=>'Cote D\'Ivorie (Ivory Coast)',
    'HR'=>'Croatia (Hrvatska)',
    'CU'=>'Cuba',
    'CY'=>'Cyprus',
    'CZ'=>'Czech Republic',
    'CD'=>'Democratic Republic Of Congo (Zaire)',
    'DK'=>'Denmark',
    'DJ'=>'Djibouti',
    'DM'=>'Dominica',
    'DO'=>'Dominican Republic',
    'TP'=>'East Timor',
    'EC'=>'Ecuador',
    'EG'=>'Egypt',
    'SV'=>'El Salvador',
    'GQ'=>'Equatorial Guinea',
    'ER'=>'Eritrea',
    'EE'=>'Estonia',
    'ET'=>'Ethiopia',
    'FK'=>'Falkland Islands (Malvinas)',
    'FO'=>'Faroe Islands',
    'FJ'=>'Fiji',
    'FI'=>'Finland',
    'FR'=>'France',
    'FX'=>'France, Metropolitan',
    'GF'=>'French Guinea',
    'PF'=>'French Polynesia',
    'TF'=>'French Southern Territories',
    'GA'=>'Gabon',
    'GM'=>'Gambia',
    'GE'=>'Georgia',
    'DE'=>'Germany',
    'GH'=>'Ghana',
    'GI'=>'Gibraltar',
    'GR'=>'Greece',
    'GL'=>'Greenland',
    'GD'=>'Grenada',
    'GP'=>'Guadeloupe',
    'GU'=>'Guam',
    'GT'=>'Guatemala',
    'GN'=>'Guinea',
    'GW'=>'Guinea-Bissau',
    'GY'=>'Guyana',
    'HT'=>'Haiti',
    'HM'=>'Heard And McDonald Islands',
    'HN'=>'Honduras',
    'HK'=>'Hong Kong',
    'HU'=>'Hungary',
    'IS'=>'Iceland',
    'IN'=>'India',
    'ID'=>'Indonesia',
    'IR'=>'Iran',
    'IQ'=>'Iraq',
    'IE'=>'Ireland',
    'IL'=>'Israel',
    'IT'=>'Italy',
    'JM'=>'Jamaica',
    'JP'=>'Japan',
    'JO'=>'Jordan',
    'KZ'=>'Kazakhstan',
    'KE'=>'Kenya',
    'KI'=>'Kiribati',
    'KW'=>'Kuwait',
    'KG'=>'Kyrgyzstan',
    'LA'=>'Laos',
    'LV'=>'Latvia',
    'LB'=>'Lebanon',
    'LS'=>'Lesotho',
    'LR'=>'Liberia',
    'LY'=>'Libya',
    'LI'=>'Liechtenstein',
    'LT'=>'Lithuania',
    'LU'=>'Luxembourg',
    'MO'=>'Macau',
    'MK'=>'Macedonia',
    'MG'=>'Madagascar',
    'MW'=>'Malawi',
    'MY'=>'Malaysia',
    'MV'=>'Maldives',
    'ML'=>'Mali',
    'MT'=>'Malta',
    'MH'=>'Marshall Islands',
    'MQ'=>'Martinique',
    'MR'=>'Mauritania',
    'MU'=>'Mauritius',
    'YT'=>'Mayotte',
    'MX'=>'Mexico',
    'FM'=>'Micronesia',
    'MD'=>'Moldova',
    'MC'=>'Monaco',
    'MN'=>'Mongolia',
    'MS'=>'Montserrat',
    'MA'=>'Morocco',
    'MZ'=>'Mozambique',
    'MM'=>'Myanmar (Burma)',
    'NA'=>'Namibia',
    'NR'=>'Nauru',
    'NP'=>'Nepal',
    'NL'=>'Netherlands',
    'AN'=>'Netherlands Antilles',
    'NC'=>'New Caledonia',
    'NZ'=>'New Zealand',
    'NI'=>'Nicaragua',
    'NE'=>'Niger',
    'NG'=>'Nigeria',
    'NU'=>'Niue',
    'NF'=>'Norfolk Island',
    'KP'=>'North Korea',
    'MP'=>'Northern Mariana Islands',
    'NO'=>'Norway',
    'OM'=>'Oman',
    'PK'=>'Pakistan',
    'PW'=>'Palau',
    'PA'=>'Panama',
    'PG'=>'Papua New Guinea',
    'PY'=>'Paraguay',
    'PE'=>'Peru',
    'PH'=>'Philippines',
    'PN'=>'Pitcairn',
    'PL'=>'Poland',
    'PT'=>'Portugal',
    'PR'=>'Puerto Rico',
    'QA'=>'Qatar',
    'RE'=>'Reunion',
    'RO'=>'Romania',
    'RU'=>'Russia',
    'RW'=>'Rwanda',
    'SH'=>'Saint Helena',
    'KN'=>'Saint Kitts And Nevis',
    'LC'=>'Saint Lucia',
    'PM'=>'Saint Pierre And Miquelon',
    'VC'=>'Saint Vincent And The Grenadines',
    'SM'=>'San Marino',
    'ST'=>'Sao Tome And Principe',
    'SA'=>'Saudi Arabia',
    'SN'=>'Senegal',
    'SC'=>'Seychelles',
    'SL'=>'Sierra Leone',
    'SG'=>'Singapore',
    'SK'=>'Slovak Republic',
    'SI'=>'Slovenia',
    'SB'=>'Solomon Islands',
    'SO'=>'Somalia',
    'ZA'=>'South Africa',
    'GS'=>'South Georgia And South Sandwich Islands',
    'KR'=>'South Korea',
    'ES'=>'Spain',
    'LK'=>'Sri Lanka',
    'SD'=>'Sudan',
    'SR'=>'Suriname',
    'SJ'=>'Svalbard And Jan Mayen',
    'SZ'=>'Swaziland',
    'SE'=>'Sweden',
    'CH'=>'Switzerland',
    'SY'=>'Syria',
    'TW'=>'Taiwan',
    'TJ'=>'Tajikistan',
    'TZ'=>'Tanzania',
    'TH'=>'Thailand',
    'TG'=>'Togo',
    'TK'=>'Tokelau',
    'TO'=>'Tonga',
    'TT'=>'Trinidad And Tobago',
    'TN'=>'Tunisia',
    'TR'=>'Turkey',
    'TM'=>'Turkmenistan',
    'TC'=>'Turks And Caicos Islands',
    'TV'=>'Tuvalu',
    'UG'=>'Uganda',
    'UA'=>'Ukraine',
    'AE'=>'United Arab Emirates',
    'UK'=>'United Kingdom',
    'US'=>'United States',
    'UM'=>'United States Minor Outlying Islands',
    'UY'=>'Uruguay',
    'UZ'=>'Uzbekistan',
    'VU'=>'Vanuatu',
    'VA'=>'Vatican City (Holy See)',
    'VE'=>'Venezuela',
    'VN'=>'Vietnam',
    'VG'=>'Virgin Islands (British)',
    'VI'=>'Virgin Islands (US)',
    'WF'=>'Wallis And Futuna Islands',
    'EH'=>'Western Sahara',
    'WS'=>'Western Samoa',
    'YE'=>'Yemen',
    'YU'=>'Yugoslavia',
    'ZM'=>'Zambia',
    'ZW'=>'Zimbabwe'
    );
    }



    Registration part
    Open register.php for editing. we loop throught the countryArray() to populate
    the dropdown menu.
    Code:

    <tr>
    <td>Country:</td><td><select size="1" name="country">
    <option value=""></option>
       <?
       
        foreach (countryArray() as $key => $value) {
       if($form->value("country") == $key) $selected = "selected";
       print '<option value="'.$key.'" ' . $selected . '>' . $value . '</option>';
       $selected = '';
    }
       
       ?>
    </select></td>
    <td><? echo $form->error("country"); ?></td>
    </tr>


    process.php
    Add the argument to the $session->editAccount function class.
    Code:

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


    session.php
    Add the argument to the editAccount function.
    Code:

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

    ...

    Country error checking
    Code:

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

    Update the database if no error occured.
    Code:

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

    That's it your done. goto Part 2 http://jpmaster77forum.conceptbb.com/php-login-system-101-f2/adding-new-option-fields-part-2-t45.htm


    Last edited by Fred-Eric on Fri Feb 27, 2009 2:49 pm; edited 1 time in total

    empecc

    Number of posts : 12
    Registration date : 2009-02-24

    Re: Adding new option fields Part 1

    Post  empecc on Thu Feb 26, 2009 7:01 am

    Can I leave country error checking?


    and is this neccesary?
    Code:

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

    Number of posts : 18
    Registration date : 2007-05-12

    Re: Adding new option fields Part 1

    Post  Admin on Thu Feb 26, 2009 9:30 am

    empecc wrote:Can I leave country error checking?
    In the countryarray there is a blank option so if a user select the blank option we want to check the error...

    BTW I am not sure about what your are saying here, Can I leave country checking, did this means you want to remove error checking?


    empecc wrote:
    and is this neccesary?
    Code:

    /* Change Country */
    if($subcountry) $database->updateUserField($this->username,"country",$subcountry);
    Of course it is necessary you have to update the country if the users change country in is life.
    avatar
    PAFaieta

    Number of posts : 8
    Registration date : 2009-03-08

    Re: Adding new option fields Part 1

    Post  PAFaieta on Sun Mar 08, 2009 6:33 pm

    I'm having problems getting the registration to work.

    I've added the fields as suggested, but just as plain text entered by the user for the sake of getting it to work initially, which it should have.

    so far, the only thing that has worked was looking up a script to hash the pass & userid and just inserting it manually.. in which case the login worked perfectly.
    avatar
    PAFaieta

    Number of posts : 8
    Registration date : 2009-03-08

    Re: Adding new option fields Part 1

    Post  PAFaieta on Mon Mar 09, 2009 12:24 am

    i found that the problem was the extra fields i added in the DB and for some reason it wasn't reading properly to register a new member. however, in my case, i had tried out an avatar field. thinking that it may have been the source of the problem, i removed that, and it still didn't work. after reverting back to the original code, it's just fine again. I'm completely lost as to what could've happened.
    avatar
    Dorji

    Number of posts : 25
    Registration date : 2009-03-30

    Help

    Post  Dorji on Fri Apr 10, 2009 1:07 pm

    Nice!!!
    But problem in getting the country namein the userinfo.php please help!!!

    Thanks
    avatar
    PAFaieta

    Number of posts : 8
    Registration date : 2009-03-08

    Re: Adding new option fields Part 1

    Post  PAFaieta on Fri Apr 10, 2009 1:18 pm

    Dorji wrote:Nice!!!
    But problem in getting the country namein the userinfo.php please help!!!

    Thanks

    the problem is that you need to add a space into the add-user function for the new field, even if it's blank, or it won't work.

    Sponsored content

    Re: Adding new option fields Part 1

    Post  Sponsored content


      Current date/time is Mon Nov 20, 2017 9:38 am