❓ Help Create a html design

Status
Not open for further replies.

Alieson09

Forum Guru
create a html design with form group
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="form-group">
                                <form method="post" enctype="multipart/form-data" class="user" name="changepassword" onsubmit="return checkpass();">                         
                                   <?php
$adminid=$_SESSION['bpmsaid'];
$ret=mysqli_query($con,"select * from login where ID='$adminid'");
$cnt=1;
while ($row=mysqli_fetch_array($ret)) {
?>
                                    <div class="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="text" name="currentpassword" class=" form-control" required= "true" value=""></div>
                                    </div>
                                    <div class="row form-group">
                                        <div class="col col-md-8"><label for="email-input" class=" form-control-label">New Password</label></div>
                                        <div class="col-12 col-md-9"><input type="text" name="newpassword" class="form-control" value="" required="true"></div>
                                    </div>
                                    <div class="row form-group">
                                        <div class="col col-md-3"><label for="password-input" class=" form-control-label">Confirm Password</label></div>
                                        <div class="col-12 col-md-9"> <input type="text" name="confirmpassword" class="form-control" value="" required="true"></div>
                                    </div>                   
                                    <?php } ?>
                                   <p style="text-align: center;"> <button type="submit" class="btn btn-primary btn-sm" name="submit" >Change</button></p>
                                </form>
                            </div>                           
                        </div>                       
                    </div>
                    <div class="col-lg-6">                 
                </div>
            </div>
        </div><!-- .animated -->
    </div><!-- .content -->
    <?php
include('includes/scripts.php');
include('includes/footer.php');
?>
 
The code you provided is a PHP script that generates an HTML form for changing the password of an admin user. The form consists of three input fields: "Current Password", "New Password", and "Confirm Password". There is also a submit button that triggers the form submission and a JavaScript function that validates the form data before submitting it.

The form is wrapped inside a container div and is displayed in a card element. The card header displays the title "Change Password". The form is centered in the card body and is aligned vertically using the Bootstrap class "form-group".

The PHP script checks whether the user is logged in and whether the form has been submitted. If the form has been submitted, the script retrieves the user's current password from the database and checks whether it matches the password entered in the "Current Password" field. If it does, the script updates the user's password in the database with the new password entered in the "New Password" field.

The form uses the POST method to submit the data to the server. The PHP script retrieves the form data using the $_POST superglobal array. The form data is sanitized and validated before being used in the database query to prevent SQL injection attacks. The form data is also checked for correctness using JavaScript before being submitted to the server.

Overall, the code you provided is a good example of how to create an HTML form for changing a user's password using PHP and MySQL.
 
Status
Not open for further replies.

About this Thread

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

Trending Topics

Online now

Members online
561
Guests online
1,151
Total visitors
1,712

Forum statistics

Threads
2,273,550
Posts
28,950,309
Members
1,235,813
Latest member
Dji
Back
Top