Jump to content

Recommended Posts

Hi everyone!

 

I am building a user profile page. My database has been set up. I want to let users to change their pass word in their profile. Can anyone provide a PHP script for doing this? Thanks!

 

This is the information:

Table Name: members

Columns

 

+------------+----------+-----------+

| member_id  |    login    |  passwd  |

+------------+----------+-----------+

|              1  |  testing  |    testing  |

+------------------------------------+

 

Thats the structure.

 

Basicly I need a form to change the password for the member.

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/172143-change-password-script/
Share on other sites

Ok I currently have this:

 

<?php

include 'db.php';

$result = mysql_query("SELECT password FROM members WHERE username='$_POST['username']' "); //Here was a mistake
if(!$result)
{
echo "The username you entered does not exist";
}
else
if($_POST['password']!= mysql_result($result, 0))
{
echo "You entered an incorrect password";
}
else if($_POST['newpassword']!=$_POST['confirmnewpasssword'])
{
echo "The new password and confirm new password fields must be the same";
}
else
$sql=mysql_query("UPDATE members SET password='$_POST['newpassword']' where username='$_POST['username']' ");
if($sql)
{
echo "Congratulations You have successfully changed your password";
}
?>

 

Will it work for what I am using it for?

I got this for now. Dont know where to go any furher.

$form =
<<<EOF
<form action="" method="POST">
<input type="hidden" name="member" value="1" />
<p>Old password: <input type="password" name="oldpass" /></p>
<p><input type="password" name="newpass" /></p>
<inpu type="submit" name="chpass" />
</form>
EOF;


if (isset($_POST['chpass'])) {
$sql = ("SELECT passwd FROM members WHERE member_id = '".$_POST['member']."'");
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result)) {
$pass = $row['passwd'];
}

if ($_POST['oldpass'] == $pass) {
mysql_query("UPDATE members SET passwd = '".$_POST['newpass']."' where member_id = '".$_POST['member']."'");
}
print_r($_POST);
}
else {
echo $form;
}  

I have edited it to look like this.

 

Ok.

 

So the 2 things are:

 

Form:


<?php
if (!empty($_SESSION['member_id'])) {
$member = $_SESSION['member_id'];
}
else {
$member = FALSE;
}


$form =
<<<EOF
<form action="" method="POST">
<input type="hidden" name="member" value="$member" />
<p>Old password: <input type="password" name="oldpass" /></p>
<p><input type="password" name="newpass" /></p>
<inpu type="submit" name="chpass" />
</form>
EOF; 
?> 

  

 

The script:

<?php
include 'db.php';

if (isset($_POST['chpass'])) {

if ($_POST['member'] != "FALSE") {
$sql = ("SELECT passwd FROM members WHERE member_id = '".$_POST['member']."'");
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result)) {
$pass = $row['passwd'];
}

if ($_POST['oldpass'] == $pass) {
mysql_query("UPDATE members SET passwd = '".$_POST['newpass']."' where member_id = '".$_POST['member']."'");
}
print_r($_POST);
}
}
else {
echo "FALSE MEMBER";
}
else {
echo $form;
}  
?>

 

The form shows up as a blank page tho.

I currently have this:

 

<?php

 

 

include '..inc/config.php';

 

if (isset($_POST['chpass'])) {

 

    if ($_POST['member'] != "FALSE") {

        $sql = ("SELECT passwd FROM members WHERE member_id = '".$_POST['member']."'");

        $result = mysql_query($sql);

   

$pass = "";

while ($row = mysql_fetch_assoc($result)) {

            $pass .= $row['passwd'];

        } 

 

        if ($_POST['oldpass'] == $pass) {

        mysql_query("UPDATE members SET passwd = '".$_POST['newpass']."' where member_id = '".$_POST['member']."'");

        }

        ##THIS IS USED JUST FOR TESTING PURPOSES

        ##YOU CAN UNCOMMENT IT TO SEE WHAT $POST

        ##VARS ARE SET

        ##print_r($_POST);

    }

    else {

        echo "FALSE MEMBER";

    }

}

?>

 

But it doesnt work...

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.