🐘 PHP Why i can't change the password from my databased?

Status
Not open for further replies.

Alieson09

Forum Guru
why i can't change the password from my databased?
Code:
<?php
session_start();
include('includes/connect.php');

if (!isset($_SESSION['bpmsaid']) || strlen($_SESSION['bpmsaid']) == 0) {
 
} else {
  if(isset($_POST['submit'])) {
    $adminid=$_SESSION['bpmsaid'];
    $cpassword=($_POST['currentpassword']);
    $newpassword=($_POST['newpassword']);
    $query=mysqli_query($con,"select ID from login where ID='$adminid' and password='$cpassword'");
    $row=mysqli_fetch_array($query);
    if($row>0){
      $ret=mysqli_query($con,"update login set password='$newpassword' where ID='$adminid'");
      echo '<script>alert("Your password successully changed.")</script>';
    }
    else {
      echo '<script>alert("Your current password is wrong.")</script>';
    }
  }
}
?>
<head>
    <title>BPMS - Change Password</title>
<script type="text/javascript">
function checkpass()
{
if(document.changepassword.newpassword.value!=document.changepassword.confirmpassword.value)
{
alert('New Password and Confirm Password field does not match');
document.changepassword.confirmpassword.focus();
return false;
}
return true;
}
</script>
</head>
<body>
   <?php include_once('includes/header.php');?>
   <?php include_once('includes/navbar.php');?>
        <div class="container">
                <div class="row">
                    <div class="col-lg-6">
                        <div class="card">                         
                        </div> <!-- .card -->
                    </div><!--/.col-->
                    <div class="col-lg-12">
                        <div class="card">
                            <div class="card-header">
                                <strong>Change </strong> Password
                            </div>
                            <div class="card-body card-block">
                                <form action="" method="post" enctype="multipart/form-data" class="user" name="changepassword" onsubmit="return checkpass();">
                                <div class="row form-group">
                                        <div class="col col-md-3"><label for="text-input" class=" form-control-label">Current Password</label></div>
                                        <div class="col-12 col-md-9"><input type="password" name="currentpassword" class=" form-control" required= "true" value=""></div>
                                    </div>
                                    <div class="row form-group">
                                        <div class="col col-md-3"><label for="email-input" class=" form-control-label">New Password</label></div>
                                        <div class="col-12 col-md-9"><input type="password" name="newpassword" class="form-control" value="" required="true"></div>
                                    </div>
                                    <div class="row form-group">
                                        <div class="col col-md-3"><label for="email-input" class=" form-control-label">Confirm Password</label></div>
                                        <div class="col-12 col-md-9"><input type="password" name="confirmpassword" class="form-control" value="" required="true"></div>
                                    </div>
                                   <p style="text-align: center;"> <button type="submit" class="btn btn-primary btn-user btn-block" name="submit" >Change</button></p>
                                </form>
                            </div>                           
                        </div>                       
                    </div>
                    <div class="col-lg-6">                 
                </div>
            </div>
        </div><!-- .animated -->
    </div><!-- .content -->
</body>
</html>
    <?php
include('includes/scripts.php');
include('includes/footer.php');
?>
 
There could be several reasons why you cannot change the password from your database. One possible reason could be that the code is not properly connecting to the database. Make sure that the connect.php file contains the correct database credentials.

Another reason could be that the SQL query for updating the password is not executing properly. You can try adding an or die(mysqli_error($con)) after the mysqli_query function to print any errors in case the query fails.

Also, make sure that the form fields for the current password, new password, and confirm password are correctly named and correspond to the variables in the PHP code.

Lastly, check if the session variable bpmsaid is properly set and contains a value. You can use var_dump($_SESSION['bpmsaid']); to print the value and check if it is set or not.
 
Status
Not open for further replies.

About this Thread

  • 1
    Replies
  • 432
    Views
  • 1
    Participants
Last reply from:
Unknown user

Trending Topics

Online now

Members online
406
Guests online
995
Total visitors
1,401

Forum statistics

Threads
2,273,593
Posts
28,950,484
Members
1,235,847
Latest member
eevaliceturtle
Back
Top