Hey there, this post would be another post under the I’m Stuck!!! series. I’d like you to know one of the things that was curious about and didn’t know that I was able to do it. And that thing is I actually knew how to make the form to change password. You know that thing when you have an account, and then it has the page where you can change your password, that’s the thing that I’m gonna share with you in this post. It’s very simple, the main idea that we’re gonna use is the UPDATE syntax. Yup, it’s that simple.

Since we need a database to store the login information, this is the database that I’ll be referring to :

Database name= company
Table name= staff

Name StaffID

admin 567

admin2 568

And the name of this page is password.php

Now the preparation’s all done, let’s head over to the fun part.
We are going to write ONLY 1 page of code, so don’t be that terrified.

Code:

<!DOCTYPE html>
<body>

<form action=”password.php” method=”POST”>
<input type=”text” name=”user”>
<input type=”text” name=”pass”>
<input type=”submit” name=”submit”>
</form>

</body>
</html>

<?php

$conn = mysqli_connect(“localhost”,”root”,””,”company”);

$user = $_POST[‘user’];

$pass = $_POST[‘pass’];

$update = “UPDATE staff SET StaffID=$pass WHERE Name=’$user'”;

if(isset($_POST[‘submit’]))
{
if(mysqli_query($conn,$update))
{
echo “Successfully changed password”;
}
else
{
echo “Error” . mysqli_error($conn);
}
}

?>

Explanation:

if(isset($_POST[submit’]))
– This piece of code means if the submit button is pressed..
– If you didn’t declare the name of the submit input, it’ll return
as an error.

That is it for this post. The most IMPORTANT part is for you to code yourself. Have a fun time changing passwords!

Any inquiries, mail me at imdad@zeroprogrammer.com