Small php help needed

Discussion in 'PHP' started by fear, Jan 3, 2010.

  1. #1
    Hi,
    I need some help with my script. Here is what I want. Its an online form that everyone sign up there and once the form is submitted it should give a unique number to everyone.
    I'm pretty sure its simple but just can't find the hint.

    Thanks in advance.

    Regards,
     
    fear, Jan 3, 2010 IP
  2. ajith107

    ajith107 Peon

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    hi,
    here is the sample that you looking for.
    ---table details------
    table name:user_details
    fields: fname varchar(15),lname varchar(15),...,UserId varchar(5)
    ----------------
    After submitting the form ,get the details from the form.
    $uid=substr(uniqid(),-5);
    insert into table along with the fname,lname,....UserId.etc //where UserId is $uid
    After successsful insertion , retrieve from the table that UserId wit respect to user and display them.

    I think this may help you..
     
    ajith107, Jan 3, 2010 IP
  3. fear

    fear Banned

    Messages:
    3,750
    Likes Received:
    221
    Best Answers:
    0
    Trophy Points:
    205
    #3
    Thanks but I didn't mean that, I'm talking about a unique number like a bank draft number. And how can I then echo it? For example:
    When a user submits the form, name, lastname, subject, will be saved in the record with a unique id number, but in next page followings should be displayed to the user.
    Id:
    Name:
    Lastname:
    Subject:
    Draft Number: (This draft number must be unique and generated by php and displayed to the user).
     
    fear, Jan 4, 2010 IP
  4. ajith107

    ajith107 Peon

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    hi,
    Whether the unique number is vary w.r.t session of the user or
    remains same and permanent for that user?
     
    ajith107, Jan 4, 2010 IP
  5. fear

    fear Banned

    Messages:
    3,750
    Likes Received:
    221
    Best Answers:
    0
    Trophy Points:
    205
    #5
    It should remain same and permanent for that user.
     
    fear, Jan 4, 2010 IP
  6. ajith107

    ajith107 Peon

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I think this may help you better than before.:)
    If you register the following details will be shown

    -------Your details --------
    First Name ramesh
    Last Name kumar
    Subject hi wish you a happy new year
    Draft No 2301e849
    -----------------------
    whenever you want this draftno use the firstname and lastname ,to get from the table.
     

    Attached Files:

    ajith107, Jan 4, 2010 IP
  7. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #7
    
    function genRandomString($length) {
        $characters = "0123456789abcdefghijklmnopqrstuvwxyz"; // you could remove letters if necessary
        $draft = "";    
        for ($p = 0; $p < $length; $p++) {
            $draft .= $characters[mt_rand(0, strlen($characters))];
        }
        return $draft;
    }
    
    PHP:
    Usage:

    
    $draft = genRandomString(5); // number 5 represents the $length of the draft number you want, longer the better I guess
    
    PHP:
    
    echo $draft;
    
    PHP:
    You will also need to store this number within your database, just like you store the username and password etc..
     
    MyVodaFone, Jan 4, 2010 IP
  8. vedicrishi

    vedicrishi Peon

    Messages:
    40
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Its pretty simple.

    Just make a function in php to generate random numbers.
    Once the registration form is submitted, call this function and display the number, it will be unique number. You can also store this number in database for future reference or email to your users.
     
    vedicrishi, Jan 4, 2010 IP
  9. fear

    fear Banned

    Messages:
    3,750
    Likes Received:
    221
    Best Answers:
    0
    Trophy Points:
    205
    #9
    I want it to be in sequence, and the starting letter should be for example
    DR1111 so next one should be DR1112 and so on....
     
    fear, Jan 5, 2010 IP
  10. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #10
    Well then wouldn't it be just a simple auto_increment, if you create a second table you could easily tie a users id to a separate draft number(auto_increment) and simple post the letters DR to the html page.

    ie: post the users id number into table2

    CREATE TABLE draft_numbers (
    user_id int(255) NOT NULL,
    draft_number int(255) NOT NULL auto_increment,
    PRIMARY KEY (draft_number)
    ) AUTO_INCREMENT=1111
     
    Last edited: Jan 5, 2010
    MyVodaFone, Jan 5, 2010 IP
  11. ajith107

    ajith107 Peon

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    hi,
    It can be in sequence as you expected.

    o/p---------------
    Your details First Name Ajith
    Last Name Kumar
    Subject Welcome
    Draft No DR1111
    ---------------
    it increase as DR1112,DR1113 etc.....
     

    Attached Files:

    ajith107, Jan 5, 2010 IP