how to change the password for already existed user in php
can anyone give me the sample code?
AntonyRayan 15 Posting Whiz in Training
milil 24 Newbie Poster
Can you give us more details what you exacly need?
You can execute sql code that will update that table.
You can go to phpmyadmin and update it from server menu.
You want to update table you created or user that belongs to database?
AntonyRayan 15 Posting Whiz in Training
This is my index.php::
<html>
<head>
<title>Registration - New User</title>
</head>
<body>
<div class="login-container">
<div class="login-header">
<h4>Sign Up</h4>
</div>
<form method="post" action="save.php">
<div class="login-field">
<label for="name"></label>
<input type="text" name="name" id="name" placeholder="Username">
<i class="icon-user"></i>
</div>
<div class="login-field">
<label for="email"></label>
<input type="text" name="email" id="email" placeholder="Email">
<i class="icon-envelope"></i>
</div>
<div class="login-field">
<label for="password"></label>
<input type="password" name="password" id="password" placeholder="Password">
<i class="icon-lock"></i>
</div>
<div class="login-button">
<button type="submit" class="btn btn-large btn-block blue">SIGN UP <i class="icon-arrow-right"></i></button>
</div>
<div class="Already a member">
<a href="login.php">Already a member</a>
</div>
</form>
</div>
</body>
</html>
After successful registration : he will go to login page:
this is login .php:
<html>
<head></head>
<body>
<div class="login-container">
<div class="login-header">
<h4>Sign in</h4>
</div>
<form method="post" action="logincheck.php">
<div class="login-field">
<label for="email"></label>
<input type="text" name="email" id="email" placeholder="Email">
<i class="icon-envelope"></i>
</div>
<div class="login-field">
<label for="password"></label>
<input type="password" name="password" id="password" placeholder="Password">
<i class="icon-lock"></i>
</div>
<div class="login-button">
<button type="submit" class="btn btn-large btn-block blue">SIGN IN <i class="icon-arrow-right"></i></button>
</div>
<div class="change-password">
<a href="changepassword.php">Change Password?</a> <a href="index.php">New User</a>
</div>
</form>
</div>
</body>
</html>
In this page if user wants to change password it will go to
change password .php
<html>
<head>
</head>
<body>
<div class="login-container">
<div class="login-header">
<h4>Change Password</h4>
</div>
<form method="post" action="checkpassword.php">
<div class="login-field">
<label for="password"></label>
<input type="password" name="password" id="password" placeholder="Old Password">
<i class="icon-lock"></i>
</div>
<div class="login-field">
<label for="password"></label>
<input type="password" name="newpassword" id="newpassword" placeholder="New Password">
<i class="icon-lock"></i>
</div>
<div class="login-field">
<label for="password"></label>
<input type="password" name="confirmpassword" id="confirmpassword" placeholder="Confirm Password" onBlur="checkPassword()">
<i class="icon-lock"></i>
</div>
<div class="login-button">
<button type="submit" class="btn btn-large btn-block blue">Change Password <i class="icon-arrow-right"></i></button>
</div>
<div class="Already a member">
<a href="login.php">Already a member</a>
</div>
</form>
</div>
</body>
</html>
After that I don`t know how to change password ,
in db, I have the faollowung fields:
id, name, email, password, only
milil 24 Newbie Poster
on your changepassword.php you have <form method="post" action="checkpassword.php"> so when you click change passwords that form will be called.
What I suggest is this. When you login put that user in session.
When you click on change password it will grab user ID from session and this new password you enterd from form. Your form is post method so you will have something like this:
$newPassword="";
if(isset($_POST["newpassword"])) {
$newPassword=$_POST["newpassword"];
}
$USERID = "";
$_SESSION["USERID"] = "USERID";
$SQL="UPDATE `USER` SET `PASSWORD` = " . $newPassword ." WHERE `USERID` =" . $USERID . ";";
So what you need to do is next:
- When login put userid in session
- If you didn't create checkpassword.php please create it because your form is calling that
- Grab values from post method and session
- Update database
- Return value
AntonyRayan 15 Posting Whiz in Training
thanks a lot
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.