# Updating membership information with PDO

**URL:** <https://www.phphelp.com/t/updating-membership-information-with-pdo/32608>\
**Category:** Beginners - Learning PHP\
**Created:** [October 2, 2020, 9:26am UTC](https://www.phphelp.com/t/updating-membership-information-with-pdo/32608 "2020-10-02T09:26:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Adem](https://www.phphelp.com/letter_avatar_proxy/v4/letter/a/a4c791/32.png) [@Adem](https://www.phphelp.com/u/Adem)\
**Post date:** [October 2, 2020, 9:26am UTC](https://www.phphelp.com/t/updating-membership-information-with-pdo/32608/1 "2020-10-02T09:26:39Z")

</div>

Hello,

When updating member information, update if a new password is entered or update password if it is empty

How is this done?

```
$stmt = $PDOdatabase->prepare("UPDATE members SET member_name=?, member_lasname=?, member_email=?, member_password_hash=? WHERE member_id=? ");

$stmt->bindParam(1, $member_name, PDO::PARAM_STR);
$stmt->bindParam(2, $member_lasname, PDO::PARAM_STR);
$stmt->bindParam(3, $member_email, PDO::PARAM_STR);
$stmt->bindParam(4, $member_password_hash, PDO::PARAM_STR);
$stmt->bindParam(5, $member_id, PDO::PARAM_STR);
```

---

<div class="post-metadata">

**Author:** ![Strider64](https://www.phphelp.com/user_avatar/www.phphelp.com/strider64/32/3161_2.png) [@Strider64](https://www.phphelp.com/u/Strider64)\
**Post date:** [October 2, 2020, 11:07am UTC](https://www.phphelp.com/t/updating-membership-information-with-pdo/32608/2 "2020-10-02T11:07:04Z")

</div>

If the user is updating the password then you have to be very careful and need to set up some verification such as sending a user an email to the person. There has to be some information in the table that can verify the user is who he/she says that the are like the email address example I gave you. I am not understanding the part of password being empty? If the password is empty then how was the user account created in the first place? If you are just setting up a test account then simply update the password field by the id.

---

<div class="post-metadata">

**Author:** ![Adem](https://www.phphelp.com/letter_avatar_proxy/v4/letter/a/a4c791/32.png) [@Adem](https://www.phphelp.com/u/Adem)\
**Post date:** [October 2, 2020, 11:46am UTC](https://www.phphelp.com/t/updating-membership-information-with-pdo/32608/3 "2020-10-02T11:46:21Z")

</div>

It sends a verification mail in case of password and mail changes. No problem here.

When editing user profile, When updating name, surname, and other information  
If he’s not changing his password, That is, if leaving the password input fields blank and pressing the update button  
Passwords in the database will not be updated, If she enters her new password in the password input fields, her password in the database will be changed.

```
if(!empty($_POST['new_password'])){
    if(empty($_POST['password_repeat'])){
        echo "Repeat password";
    }else{
        if($_POST['new_password'] == $_POST['password_repeat']){
            $member_password_hash = password_hash(filter_input(INPUT_POST, 'new_password'), PASSWORD_DEFAULT);
        }else{
            echo "Passwords do not match";
        }
    }
}else{

}

```

My question is how should I make a database from now on

While using MySQLi I was doing as follows

```
if(!empty($_POST['new_password']) AND !empty($_POST['password_repeat'])){
    $member_password_hash = ", member_password_hash='".$this->member_password_hash."'";
}else{
    $member_password_hash = "";
}
```

---

<div class="post-metadata">

**Author:** ![skawid](https://www.phphelp.com/letter_avatar_proxy/v4/letter/s/bbe5ce/32.png) [@skawid](https://www.phphelp.com/u/skawid)\
**Post date:** [October 2, 2020, 12:43pm UTC](https://www.phphelp.com/t/updating-membership-information-with-pdo/32608/4 "2020-10-02T12:43:58Z")

</div>

If you sometimes don’t want the password to be upated, you need to change your query to sometimes not accept a password parameter.

Backing up a little, this is usually handled by having a separate form to update the password.

---

<div class="post-metadata">

**Author:** ![Adem](https://www.phphelp.com/letter_avatar_proxy/v4/letter/a/a4c791/32.png) [@Adem](https://www.phphelp.com/u/Adem)\
**Post date:** [October 3, 2020, 7:33am UTC](https://www.phphelp.com/t/updating-membership-information-with-pdo/32608/5 "2020-10-03T07:33:43Z")

</div>

Can’t PDO be done like MySQLi?
