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 fields Part 1

    Share
    avatar
    Fred-Eric

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

    Adding new fields Part 1

    Post  Fred-Eric on Tue Feb 24, 2009 9:13 pm

    Adding new control input element in a form, Part 1

    In order to accomplish the task of adding new control input element we will modified theses files:
    [*] register.php
    [*] process.php
    [*] session.php
    [*] database.php

    Also we will need to alter the current users table to accept the new field created.


    1- Altering the sql table
    Usually, to accomplish that task I use phpmyadmin, very simple to use...
    Just execute this query.
    Code:

    ALTER TABLE `users` ADD `firstname` VARCHAR( 32 ) NOT NULL ;


    2- Edit register.php and add the new control input element into the form.
    Code:

    <!-- this is the new part -->
    <tr>
    <td>Firstname:</td>
    <td><input type="text" name="firstname" maxlength="32" value="<? echo $form->value("firstname"); ?>"></td>
    <td><? echo $form->error("firstname"); ?></td>
    </tr>
    <!-- end new part -->
    It should be like this after.
    Code:

    <form action="process.php" method="POST">
    <table align="left" border="0" cellspacing="0" cellpadding="3">
    <tr>
    <td>Username:</td>
    <td><input type="text" name="user" maxlength="30" value="<? echo $form->value("user"); ?>"></td>
    <td><? echo $form->error("user"); ?></td>
    </tr>
    <tr>
    <td>Password:</td>
    <td><input type="password" name="pass" maxlength="30" value="<? echo $form->value("pass"); ?>"></td>
    <td><? echo $form->error("pass"); ?></td>
    </tr>
    <tr>
    <td>Email:</td><td><input type="text" name="email" maxlength="50" value="<? echo $form->value("email"); ?>"></td>
    <td><? echo $form->error("email"); ?></td>
    </tr>

    <!-- this is the new part -->
    <tr>
    <td>Firstname:</td><td><input type="text" name="firstname" maxlength="32" value="<? echo $form->value("firstname"); ?>"></td>
    <td><? echo $form->error("firstname"); ?></td>
    </tr>
    <tr>
    <!-- end new part -->

    <td colspan="2" align="right">
    <input type="hidden" name="subjoin" value="1">
    <input type="submit" value="Join!">
    </td>
    </tr>
    <tr>
    <td colspan="2" align="left"><a href="main.php">Back to Main</a>
    </td>
    </tr>
    </table>
    </form>

    3- Edit process.php and find the function call procRegister().
    Add the posted value $_POST[firstname] as a new argument to the $session->register($_POST['user'], $_POST['pass'], $_POST['email'], $_POST['firstname']);.
    Code:

    /* Registration attempt */
    $retval = $session->register($_POST['user'], $_POST['pass'], $_POST['email'], $_POST['firstname']);


    4.1- Edit session.php and find the function call register()
    Make sure to add the new $argument to that function
    Code:

    function register($subuser, $subpass, $subemail, $subfirstname){

    4.2- Somewhere in the function you will need to check the for value error.
    Code:

    /*Firstname error checking */
    $field = "firstname";
    if(!$subfirstname || strlen($subfirstname = trim($subfirstname)) == 0) $form->setError($field, "* firstname not entered");
    $subfirstname = stripslashes($subfirstname);

    4.3- Then, if no error is found in the form you will send the info to the DB using $database->addnewuser() class function.
    Code:

    $database->addNewUser($subuser, md5($subpass), $subemail, $subfirstname))

    5- Edit database.php and find the function call addNewUser().
    Code:

    /**
        * addNewUser - Inserts the given (username, password, email)
        * info into the database. Appropriate user level is set.
        * Returns true on success, false otherwise.
        */
      function addNewUser($username, $password, $email, $firstname){
          $time = time();
          /* If admin sign up, give admin user level */
          if(strcasecmp($username, ADMIN_NAME) == 0){
            $ulevel = ADMIN_LEVEL;
          }else{
            $ulevel = USER_LEVEL;
          }
          $q = "INSERT INTO ".TBL_USERS." VALUES ('$username', '$password', '0', $ulevel, '$email', $time, '$firstname')";
          return mysql_query($q, $this->connection);
      }

    that's it your done...


    Last edited by Fred-Eric on Sat Mar 14, 2009 7:47 pm; edited 5 times in total
    avatar
    mr_roo

    Number of posts : 3
    Registration date : 2010-02-11

    Trouble adding multiple fields

    Post  mr_roo on Sat Feb 13, 2010 12:13 am

    I have attempted to add multiple fields, and every field after the first one, is giving me an error that it has been left empty. Is anyone that has added multiple fields able to help me?
    avatar
    mattastic

    Number of posts : 25
    Registration date : 2009-10-11

    Re: Adding new fields Part 1

    Post  mattastic on Sat Feb 13, 2010 11:42 am

    what is the error message?
    avatar
    mr_roo

    Number of posts : 3
    Registration date : 2010-02-11

    Re: Adding new fields Part 1

    Post  mr_roo on Sun Feb 14, 2010 2:40 am

    Fixed it, I forgot to edit session.php and have it retrieve the new variables that I added to the registration.
    avatar
    meadsy25

    Number of posts : 13
    Registration date : 2011-08-22

    Re: Adding new fields Part 1

    Post  meadsy25 on Mon Aug 22, 2011 6:15 pm

    Thanks for the tutorial, I have followed the steps but keep getting an error message:

    We're sorry, but an error has occurred and your registration for the username richard, could not be completed.
    Please try again at a later time.

    What would I be doing wrong?
    avatar
    meadsy25

    Number of posts : 13
    Registration date : 2011-08-22

    Re: Adding new fields Part 1

    Post  meadsy25 on Tue Aug 23, 2011 5:12 am

    ahh, no I've seemed to have fixed that...

    but like mr roo I have the issue where nothing seems to get registered from the form after the first new field. All fields and variables seem to be registered following the tutorial.

    Any one else had the same issue? Mr Roo what was your fix?

    Cheers
    avatar
    rissvann

    Number of posts : 3
    Registration date : 2011-08-26

    Re: Adding new fields Part 1

    Post  rissvann on Fri Aug 26, 2011 10:10 pm

    I have added multiple fields & update each file accordingly which you mentioned here but now i am unable to insert newly fields data into my database whereas all the default fields data are inserting successfully. Can you suggest me how can i debug it?
    avatar
    meadsy25

    Number of posts : 13
    Registration date : 2011-08-22

    Re: Adding new fields Part 1

    Post  meadsy25 on Tue Aug 30, 2011 4:02 pm

    Can anyone help?
    avatar
    rissvann

    Number of posts : 3
    Registration date : 2011-08-26

    Re: Adding new fields Part 1

    Post  rissvann on Tue Aug 30, 2011 7:25 pm

    What sort of help you required?
    meadsy25 wrote:Can anyone help?
    avatar
    meadsy25

    Number of posts : 13
    Registration date : 2011-08-22

    Re: Adding new fields Part 1

    Post  meadsy25 on Wed Aug 31, 2011 2:30 am

    Same as you. My post is above yours with the same issues.
    avatar
    rissvann

    Number of posts : 3
    Registration date : 2011-08-26

    Re: Adding new fields Part 1

    Post  rissvann on Sun Sep 04, 2011 6:05 pm

    Seems like that no one here to help use Sad
    meadsy25 wrote:Same as you. My post is above yours with the same issues.
    avatar
    Siggles

    Number of posts : 11
    Registration date : 2011-09-03

    Re: Adding new fields Part 1

    Post  Siggles on Mon Sep 05, 2011 11:52 am

    rissvann wrote:Seems like that no one here to help use Sad
    meadsy25 wrote:Same as you. My post is above yours with the same issues.

    Hi, I'll try and help. I'm also updating the script as we speak, trying to make it more user friendly so watch this space..

    The best thing to try and fix this is to back track I think, starting with database.php..

    please check database.php and the insert query..

    Code:
    $q = "INSERT INTO ".TBL_USERS." VALUES ('$username', '$password', '0', $ulevel, '$email', $time, '$firstname')"

    Dont forget that Fred-Eric added the firstname variable at the end of the query, your query should end with $time and then the name of the variable you chose/are using.

    And the same here.

    Code:
    function addNewUser($username, $password, $email, $firstname){

    It should be $email and then your variable.

    The variable you put at the end of the query should be indentical to what is in the form field and also what you put at the end of the code ins tep 3...

    Code:

    /* Registration attempt */
    $retval = $session->register($_POST['user'], $_POST['pass'], $_POST['email'], $_POST['firstname']);

    Maybe start there.
    avatar
    meadsy25

    Number of posts : 13
    Registration date : 2011-08-22

    Re: Adding new fields Part 1

    Post  meadsy25 on Mon Sep 05, 2011 4:30 pm

    Thank you for your help.

    I've been through my code as you've suggested. Noting unusual, I'm confident all is fine there. I could just be missing the wood for the trees though.

    seems a strange one.

    In reverse

    Code:
    $q = "INSERT INTO ".TBL_USERS." VALUES ('$username', '$password', '0', $ulevel, '$email', $time, '$ac_f_name', '$ac_l_name', '$ac_add1', '$ac_add2', '$ac_city', '$ac_county', '$ac_country', '$ac_postcode', '$ac_phone', '$ac_mobile', '$ac_mail')";

    Then

    Code:
    function addNewUser($username, $password, $email, $ac_f_name, $ac_l_name, $ac_add1, $ac_add2, $ac_city, $ac_county, $ac_country, $ac_postcode, $ac_phone, $ac_mobile, $ac_mail){

    and

    Code:
     $retval = $session->register($_POST['user'], $_POST['pass'], $_POST['email'], $_POST['ac_f_name'], $_POST['$ac_l_name'], $_POST['$ac_add1'], $_POST['$ac_add2'], $_POST['$ac_city'], $_POST['$ac_county'], $_POST['$ac_country'], $_POST['$ac_postcode'], $_POST['$ac_phone'], $_POST['$ac_mobile'], $_POST['$ac_mail']);

    ?
    avatar
    Siggles

    Number of posts : 11
    Registration date : 2011-09-03

    Re: Adding new fields Part 1

    Post  Siggles on Tue Sep 06, 2011 3:33 am

    Can you post up your session.php changes?
    avatar
    meadsy25

    Number of posts : 13
    Registration date : 2011-08-22

    Re: Adding new fields Part 1

    Post  meadsy25 on Tue Sep 06, 2011 3:41 am

    Not sure which bit? Or if this is the problem? But again as the ac_f_name gets registered I would assume the rest should.

    Code:
     function register($subuser, $subpass, $subemail, $subac_f_name, $subac_l_name, $subac_add1, $subac_add2, $subac_city, $subac_county, $subac_country, $subac_postcode, $subac_phone, $subac_mobile, $subac_mail){

    Code:
     if($database->addNewUser($subuser, md5($subpass), $subemail, $subac_f_name, $subac_l_name, $subac_add1, $subac_add2, $subac_city, $subac_county, $subac_country, $subac_postcode, $subac_phone, $subac_mobile, $subac_mail)){
    avatar
    b0bby

    Number of posts : 2
    Registration date : 2011-09-12

    Re: Adding new fields Part 1

    Post  b0bby on Tue Sep 13, 2011 5:39 am

    i've added new tables but now my registration doesnt work anymore
    avatar
    meadsy25

    Number of posts : 13
    Registration date : 2011-08-22

    Re: Adding new fields Part 1

    Post  meadsy25 on Tue Sep 20, 2011 6:38 am

    I'd look for a new function if I were you. I've spent hours going over it and cannot work out what I'm doing wrong or why it just will not work. And there doesn't seem to be anyone here who can help.
    avatar
    Linchpin311

    Number of posts : 220
    Age : 32
    Localisation : Long Island
    Registration date : 2007-05-14

    Re: Adding new fields Part 1

    Post  Linchpin311 on Tue Sep 20, 2011 9:20 pm

    ok so i read the entire thread, but i want to make sure i understand. what are you trying to do and what errors are you receiving?


    _________________
    in the end, the universe tends to unfold as it should...

    Also note that it is your responsibility to die() if necessary.
    avatar
    meadsy25

    Number of posts : 13
    Registration date : 2011-08-22

    Re: Adding new fields Part 1

    Post  meadsy25 on Wed Sep 21, 2011 4:46 am

    Stunning.

    I've added some extra fields to the form so I can collect address details for the account.

    I have set them up following the 'Adding new fields Part 1' guide The first new field was ac_f_name which adds as described in the this thread, but all other fields, which were added in exactly the same way will not write to the database.
    avatar
    Siggles

    Number of posts : 11
    Registration date : 2011-09-03

    Re: Adding new fields Part 1

    Post  Siggles on Wed Sep 21, 2011 4:58 am

    Meadsy, how about zipping up your files for download (minus your constants file) and we can take a look? Or even copying each seperate page code on to this post?
    avatar
    meadsy25

    Number of posts : 13
    Registration date : 2011-08-22

    Re: Adding new fields Part 1

    Post  meadsy25 on Wed Sep 21, 2011 8:00 am

    I've zipped the files and added them here.



    Cheers
    Rich


    Last edited by meadsy25 on Wed Sep 21, 2011 4:14 pm; edited 1 time in total
    avatar
    Siggles

    Number of posts : 11
    Registration date : 2011-09-03

    Re: Adding new fields Part 1

    Post  Siggles on Wed Sep 21, 2011 8:35 am

    Nice one, any chance you can put a pic of your database structure. phpMyAdmin screenshot maybe? The users table and columns? I'll look at what you sent in the meantime.
    avatar
    meadsy25

    Number of posts : 13
    Registration date : 2011-08-22

    Re: Adding new fields Part 1

    Post  meadsy25 on Wed Sep 21, 2011 10:51 am

    [img][/img]
    avatar
    Siggles

    Number of posts : 11
    Registration date : 2011-09-03

    Re: Adding new fields Part 1

    Post  Siggles on Wed Sep 21, 2011 11:18 am

    Check session.php line 357
    Code:
     else{
            if($database->addNewUser($subuser, md5($subpass), $subemail, [b]$subac_f_name[/b], $subac_l_name, [b]$subac_f_name[/b], $subac_f_name, $subac_city, $subac_county, $subac_country, $subac_postcode, $subac_phone, $subac_mobile, $subac_mail)){
    avatar
    meadsy25

    Number of posts : 13
    Registration date : 2011-08-22

    Re: Adding new fields Part 1

    Post  meadsy25 on Wed Sep 21, 2011 12:09 pm

    Ahh yes, as I know ac_f_name was posting I did that to see if it woudl right taht value. When I change it to the correct values it still doesn't work.

    Code:
    else{
            if($database->addNewUser($subuser, md5($subpass), $subemail, $subac_f_name, $subac_l_name, $subac_add1, $subac_add2, $subac_city, $subac_county, $subac_country, $subac_postcode, $subac_phone, $subac_mobile, $subac_mail)){

    Sponsored content

    Re: Adding new fields Part 1

    Post  Sponsored content


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