• We just launched and are currently in beta. Join us as we build and grow the community.

Update Password using PHP

omeganoova

Software Architect
O Rep
0
0
0
Rep
0
O Vouches
0
0
0
Vouches
0
Posts
84
Likes
165
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 200 XP
If you are looking for on how to Update Password u then you are at the right place. the right place. This simple tutorial creates using PHP/MySQL. The feature of this tutorial is to change the password from the database. It contains the Old Password from the database, New Password, and Re-Type New Password. Almost in web projects, changing password is important.

Create Markup Form

This simple HTML source code below contains three TextBox for the Old Password, New Password, and Re-Type Password. Where the user can update the password from the database. Review the source code below.

  1. <div

    style

    =

    "width:30%;"

    >
  2. <form

    method

    =

    "post"

    action

    =

    "change-password.php"

    >
  3. <div

    >
  4. <label

    style

    =

    "color:blue;"

    >

    Old Password</

    label

    >
  5. <input

    type

    =

    "password"

    name

    =

    "old_pass"

    placeholder=

    "Old Password . . . . ."

    >
  6. </

    div

    >
  7. <div

    >
  8. <label

    style

    =

    "color:blue;"

    >

    New Password</

    label

    >
  9. <input

    type

    =

    "password"

    name

    =

    "new_pass"

    placeholder=

    "New Password . . . . ."

    >
  10. </

    div

    >
  11. <div

    >
  12. <label

    style

    =

    "color:blue;"

    >

    Re-Type New Password</

    label

    >
  13. <input

    type

    =

    "password"

    name

    =

    "re_pass"

    placeholder=

    "Re-Type New Password . . . . ."

    >
  14. </

    div

    >
  15. <button

    type

    =

    "submit"

    name

    =

    "re_password"

    >

    Submit</

    button

    >
  16. </

    form

    >
  17. </

    div

    >

Create Database Connection

This would be your database connection.

  1. <?php
  2. $database_connection

    =

    mysql_connect

    (

    "localhost"

    ,

    "root"

    ,

    ""

    )

    or die

    (

    )

    ;
  3. $select_database

    =

    mysql_select_db

    (

    "change_password"

    ,

    $database_connection

    )

    or die

    (

    )

    ;
  4. ?>

This is the PHP query where the UPDATE Statement is used to change the password from the database.

  1. <?php

  2. if

    (

    isset

    (

    $_POST

    [

    're_password'

    ]

    )

    )
  3. {
  4. $old_pass

    =

    $_POST

    [

    'old_pass'

    ]

    ;
  5. $new_pass

    =

    $_POST

    [

    'new_pass'

    ]

    ;
  6. $re_pass

    =

    $_POST

    [

    're_pass'

    ]

    ;
  7. $password_query

    =

    mysql_query

    (

    "select * from users where id='1'"

    )

    ;
  8. $password_row

    =

    mysql_fetch_array

    (

    $password_query

    )

    ;
  9. $database_password

    =

    $password_row

    [

    'password'

    ]

    ;
  10. if

    (

    $database_password

    ==

    $old_pass

    )
  11. {
  12. if

    (

    $new_pass

    ==

    $re_pass

    )
  13. {
  14. $update_pwd

    =

    mysql_query

    (

    "update users set password='$new_pass

    ' where id='1'"

    )

    ;
  15. echo

    "<script>alert('Update Sucessfully'); window.location='index.php'</script>"

    ;
  16. }
  17. else
  18. {
  19. echo

    "<script>alert('Your new and Retype Password is not match'); window.location='index.php'</script>"

    ;
  20. }
  21. }
  22. else
  23. {
  24. echo

    "<script>alert('Your old password is wrong'); window.location='index.php'</script>"

    ;
  25. }
  26. }

  27. ?>

Database Name: change_password.sql

Compile all the source code as you can see above to have this simple tutorial to change a password from the database or kindly click the "Download Code" button below for the full source code. Try and enjoy coding. Thank you.


Download
You must upgrade your account or reply in the thread to view the hidden content.
 

452,496

338,631

338,639

Top