Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    May 2013
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Profile data not changed after update

    I apologize if the title not conform with the problem that I face.

    Let's say I want to change my data. Below is the old data:
    Email: testing@testing.com
    PayPal Email: paypal@testing.com
    Password: (Leave blank if you do not wish to change your password.)


    Now, I want to change it to:
    Email: mymail@gogogo.com
    PayPal Email: paypal@gogogo.com
    Password: gogogo


    I tried to change my profile data, but after I click "Update", it give me no change. Only the old data is still saved.


    Here's the code

    PHP Code:
    <?php
    require("includes/inc.php");
     
      if (
    $_SESSION['username'] == null){
      
    //Redirect the user to the login area if they're not logged in
      
    header('Location: login.php');
      exit();
      }
      
    //Check if the user is trying to logout
      
    if ($_GET['page'] == "logout") {
        
    //Unset the session and redirect the user to the login page
        
    unset($_SESSION['username']);
        
    header('Location: login.php?success=logout');
            exit();
      }
      
    //Check if the user is trying to view their account
      
    if ($_GET['page'] == "account_save") {
        
    //Post variables
        
    $email trim(sanitize($_POST['email']));
            
    $ppemail trim(sanitize($_POST['ppemail']));
        
    $password trim(sanitize($_POST['password']));
        
    // Check if the email field is blank
        
    if ($email == null || $ppemail == null){
          
    header('member.php?page=account&error=email_blank');
              exit();
        } else {
          
    //Check if email is in the valid format
          
    if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$"$email) || !eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$"$ppemail)){
            
    // Email is invalid
            
    header('Location: member.php?page=account&error=email_invalid');
                    exit();
          } else {
            
    //Update account
            
    $update_email mysql_query("UPDATE users SET email='$email', ppemail='$ppemail' WHERE `username` = '$user[username]'") or die("Couldn't update mysql database");
            
    //Update their password if it wasn't blank
            
    if ($password != null){
              
    $update_password mysql_query("UPDATE users SET password = '" password($password) . "' WHERE `username` = '$user[username]'") or die("Couldn't update the password");
            }
            
    header('Location: member.php?page=account&success=updated');
                    exit();
          }
        }
    }
    ?>



    Can someone help me?

    Thanks in advance.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Open your error reporting up or check your error logs. You'll have an error indicating that 'username' is an invalid associative index, and $user is an undefined variable. In both queries you are checking for $user['username'], which has not been declared in this script anywhere. Therefore, you update WHERE username = NULL which of course will match nothing (since even NULL <> NULL). It's not an error so it won't trigger the die, but will successfully update 0 records.
    Eregi is long old school. Use filter_var instead with FILTER_VALIDATE_EMAIL. It's not perfect, but its better than the pattern currently used.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    New Coder
    Join Date
    Apr 2013
    Posts
    39
    Thanks
    2
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by Fou-Lu View Post
    Open your error reporting up or check your error logs. You'll have an error indicating that 'username' is an invalid associative index, and $user is an undefined variable. In both queries you are checking for $user['username'], which has not been declared in this script anywhere. Therefore, you update WHERE username = NULL which of course will match nothing (since even NULL <> NULL). It's not an error so it won't trigger the die, but will successfully update 0 records.
    Eregi is long old school. Use filter_var instead with FILTER_VALIDATE_EMAIL. It's not perfect, but its better than the pattern currently used.
    Moderator pointed out a big bug on your code. You did not define $user['username'] in your program and so it cannot update


  •  

    Tags for this Thread

    Posting Permissions

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