SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Jun 2007
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP Code: Requesting MySQL info

    The Problem:
    All i want to do is when a new client is added to our site using a form which is saved to our MySQL database via a PHP page. the PHP picks up the users' MySQL data base details and puts them into a file by using the unique code which is there username.

    eg. i have 100 users and all i want is the details for user 88

    MySQL DBase:

    User ID: 88 (hidden - autonumber)
    UserName: johnnyc (used for login - unique primary key)
    Name: Mr Johnny Cash
    Address: 8 Win Streak Drive, Washington DC, USA 90210
    Phone: +1 555 5123
    eMail: xyz@gov.ua


    Now, on the page all i want is Johhny's details that can be edited by a form. The retreval must be from the login id / username. I don't want the details from someone else and i don't want to publish by myself a seperate page for each user. I just want there details to automatically come up without anyone elses. Basically there's 2 pages with various user details to be added and 9 pages with general info which dont need to be customised.

    can someone give me some code or a link to get more info or help.

  2. #2
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I constructed a data-aware user object, which when passed a unique identifier loads itself with the users information. I store this user object in a session variable, when I want to edit the user data I call a form which checks for this object and if it exist I display a filled form ready for editing.
    Computers and Fire ...
    In the hands of the inexperienced or uneducated,
    the results can be disastrous.
    While the professional can tame, master even conquer.

  3. #3
    SitePoint Member
    Join Date
    Jun 2007
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    how would i do that? i have some php / html knowledge to get me by day to day but sometimes i get a curly one.

  4. #4
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    class user {

         var 
    $User_ID;
         var 
    $UserName;
         var 
    $Name;
         var 
    $Address;
         var 
    $Phone;
         var 
    $eMail;

    function 
    getData $UserName) {
        
    $query "select * from users where UserName ='" .$UserName"'";
        
    /* code goes here to open database */

        
    $results mysql_query$query );
        if ( 
    $results ) {
            
    $row mysql_fetch_assoc$results );
            
    $this->UserName $UserName;
            
    $this->User_ID $row['User_ID'];
            
    $this->Name $row['Name'];
            
    /* code goes here to finish loading data values into object attributes */

            
    unset( $row );
        }
        
    mysql_free_result$result );
        
    mysql_close();
    }

    This is the basic layout of a data-aware class, I think you can get an ideal of what the object does and how to complete.
    Put this code in a file and call it "user.cls" , modify to you are comfortable with it
    Computers and Fire ...
    In the hands of the inexperienced or uneducated,
    the results can be disastrous.
    While the professional can tame, master even conquer.

  5. #5
    SitePoint Member
    Join Date
    Jun 2007
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks byron i'll try it... i'm going to bed 1st its 5 am now


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •