SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Zealot
    Join Date
    Apr 2003
    Location
    Texas, USA
    Posts
    139
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Allowing members to change their info

    Hi,

    I'm trying to allow my members to login to their accounts, and change their personal info (name, email address, password, etc...)

    It all seems okay, except that the table that suppose to show members' information is empty. Of course, I'm using the Value="" attribute. But it's not working.

    This is the login form
    HTML Code:
    <form name="login" method="post" action="validate.php">
    <table width="70%" border="0" cellpadding="4" cellspacing="0">
    <tr>
    <td>username:</td>
    <td><input type="text" name="username"></td>
    </tr>
    <tr>
    <td>password:</td>
    <td><input type="password" name="password"></td>
    </tr>
    <tr>
    <td align="left" valign="top">&nbsp;</td>
    <td><input type="submit" value="submit"></td>
    </tr>
    </table>
    </form>
    Which submit to the Validate.php below

    PHP Code:
    <?
    session_start
    ();

    // Connect to the database server 
       
    $dbcnx = @mysql_connect("localhost""cash""****");
       if (!
    $dbcnx) { 
         echo( 
    "<p>Unable to connect to the " 
               
    "database server at this time.</p>" ); 
         exit(); 
       } 

    // Select the database
       
    if (! @mysql_select_db("needforcash_com") ) { 
         echo( 
    "<p>Unable to locate the " .
               
    "database at this time.</p >" ); 
         exit(); 
       }

    // Conver to simple variables
    $username $_POST['username'];
    $password $_POST['password'];

    if((!
    $username) || (!$password)){
        echo 
    "Please enter ALL of the information! <br />";
        
    header("Location: login.php");
        exit();
    }

    // check if the user info validates the db
    $sql mysql_query("SELECT * FROM users WHERE username='$username' AND password='$password'");
    $login_check mysql_num_rows($sql);

    if(
    $login_check 0){
                         
    $_SESSION['username'] = $username;
                         
    $_SESSION['password'] = $password;
                         
    $_SESSION['emailaddress'] = $emailaddress;
                         
    $_SESSION['country'] = $country;
                         
    $_SESSION['firstname'] = $firstname;
                         
    $_SESSION['lastname'] = $lastname;
                         
    mysql_query("UPDATE users SET lastlogin=now() WHERE username='$username'");
                         
    header("Location: login_success.php");
    }
    else {
             echo 
    "You could not be logged in! Either the username or password are not correct<br />
        Please try again!<br />"
    ;
        
    header("Location: login.php");
    }

    ?>
    If the member is validated, he/she is taken to login_success.php page. This is a simple welcome page with one line that asks people to "click here to change their info". This is login_success.php

    PHP Code:
    <?
    include ("verifylogin.php");
    ?>

    <html>
    <head>
    <title></title>
    </head>
    <body>
    <a href="info.php">Click here to update your information</a>
    </body>
    </html>
    As you can see, the above script INCLUDEs VerifyLogin.php which is:

    PHP Code:
    <?
    session_start
    ();
    if(empty(
    $_SESSION['username'])) {
    die(
    'An error has ocurred. You have not logged in, or your session has expired. Try <a href="login.html">loggin in</a>again.');
    }
    ?>
    Anyway, when the member in the login_success.php page clicks the link to change his personal info, he will be directed to info.php. In there, they will find this form:

    HTML Code:
    <form name="changeinfo" method="post" action="updateinfo.php">
    <table width="100%" border="0" cellpadding="4" cellspacing="0">
    <tr>
    <td width="24%" align="left" valign="top">First Name</td>
    <td width="76%"><input name="firstname" type="text" value="<? echo $firstname; ?>"></td>
    </tr>
    <tr>
    <td align="left" valign="top">Last Name</td>
    <td><input name="lastname" type="text" value="<? echo $lastname; ?>"></td>
    </tr>
    <tr>
    <td align="left" valign="top">Email Address</td>
    <td><input name="emailaddress" type="text" value="<? echo $emailaddress; ?>"></td>
    </tr>
    <tr>
    <td align="left" valign="top">password</td>
    <td><input name="password" type="text" value="<? echo $password; ?>"></td>
    </tr>
    <tr>
    <td align="left" valign="top">Country</td>
    <td><input name="country" type="text" value="<? echo $country; ?>"></td>
    </tr>
    <tr>
    <td align="left" valign="top">&nbsp;</td>
    <td><input type="submit" name="Submit" value="update"></td>
    </tr>
    </table>
    </form>
    The above form is the problem. The fields are empty EXCEPT the password field, which displays the password just fine! I don't know what's wrong with the other fields!

    What do you think?

    PS: I'm using PHP 4.2.2, and the Register Globals "suppose" to be on (I think).

    Thanks. I appriciate any help you guys can give me.

    Jimmy.

  2. #2
    SitePoint Zealot
    Join Date
    Dec 2001
    Location
    UK
    Posts
    105
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you want the variables and their contents to be used on another page you will need to call the $_SESSION[] vars you have set up. Don't forget to include the session_start() before any headers have been printed. E.g.
    PHP Code:
    <?php
      session_start
    ()
    ?>
    .
    .
    .
    <td align="left" valign="top">Country</td>
    <td><input name="country" type="text" value="<?= $_SESSION['country']; ?>"></td>
    </tr>
    .
    .
    .

  3. #3
    SitePoint Zealot
    Join Date
    Apr 2003
    Location
    Texas, USA
    Posts
    139
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you for your answer. I have tried what you suggested.

    Same thing. It worked for the Password field only. The rest are blanks!

    This is very strange.

  4. #4
    SitePoint Zealot
    Join Date
    Dec 2001
    Location
    UK
    Posts
    105
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you sure those variables actually contain data! Print them out after you believe they are set to be absolutely 100% certain!

  5. #5
    SitePoint Zealot
    Join Date
    Apr 2003
    Location
    Texas, USA
    Posts
    139
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes. I used a registeration form to submit data to the MySQL database. I accessed the database then by using phpMyAdmin. The data is there!

    In the Validate.php script, I register the variables using $_SESSION

    PHP Code:
    $sql mysql_query("SELECT * FROM users WHERE username='$username' AND password='$password'" ); 
    $login_check mysql_num_rows($sql);
    if(
    $login_check 0){ 
    $_SESSION['username'] = $username
    $_SESSION['password'] = $password
    $_SESSION['emailaddress'] = $emailaddress
    $_SESSION['country'] = $country
    $_SESSION['firstname'] = $firstname
    $_SESSION['lastname'] = $lastname;
    header("Location: login_success.php" ); 

    Shouldn't the above retrieve the refered-to data and store them as variables?

    In the login_success.php page, I tried to expierment a little.

    The following worked:

    PHP Code:
    Welcome <?=$username?>
    Only $username or $password work. Any other data doesn't display!

    Does this got anything to do with the login form since those are two required info?

    I've tried everything I can think of all day. I read the www.php.net/session page, and just about every Session tutorial there is. I still don't understand why this is happening.

    Any help would be very much appriciated

  6. #6
    SitePoint Zealot
    Join Date
    Dec 2001
    Location
    UK
    Posts
    105
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do a
    PHP Code:
    print_r($_SESSION); 
    at the top of the login_success.php page. I bet those other fields are empty! Where are you setting:

    $emailaddress
    $country
    $firstname
    $lastname

    Shouldn't the code be something like:
    PHP Code:
    $login_check  mysql_num_rows($sql);

    if (
    $login_check 0) {
        
    $mem_details mysql_fetch_assoc($sql);
        
    $_SESSION['username'] = $username
        
    $_SESSION['password'] = $password
        
    $_SESSION['emailaddress'] = $row['emailaddress']; 
        
    $_SESSION['country'] = $row['country']; 
        
    $_SESSION['firstname'] = $row['firstname']; 
        
    $_SESSION['lastname'] = $row['lastname'];


  7. #7
    SitePoint Zealot
    Join Date
    Apr 2003
    Location
    Texas, USA
    Posts
    139
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You actually mean:

    PHP Code:
    $login_check mysql_num_rows($sql);

    if(
    $login_check 0){
    $mem_details mysql_fetch_assoc($sql);
    $_SESSION['username'] = $username;
    $_SESSION['password'] = $password;
    $_SESSION['emailaddress'] = $mem_details['emailaddress'];
    $_SESSION['country'] = $mem_details['country'];
    $_SESSION['firstname'] = $mem_details['firstname'];
    $_SESSION['lastname'] = $mem_details['lastname']; 
    Yes, it finally worked, and so is the Info.php page. Thank you! I appriciate your help. I got this from a tutorial. I don't know why the writer didn't include mysql_fetch.

    Thank you for your time

    Jimmy.
    Last edited by jimmy2003; May 16, 2003 at 01:13.


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
  •