Russia Posted August 27, 2009 Share Posted August 27, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/172143-change-password-script/ Share on other sites More sharing options...
ignace Posted August 27, 2009 Share Posted August 27, 2009 Can anyone provide a PHP script for doing this? If you are looking for someone to write something for you then you should have posted in the freelance section. Quote Link to comment https://forums.phpfreaks.com/topic/172143-change-password-script/#findComment-907652 Share on other sites More sharing options...
Russia Posted August 27, 2009 Author Share Posted August 27, 2009 Its something simple, so I really do not thingk I should be paying, basicly its updates the database with a new password. Quote Link to comment https://forums.phpfreaks.com/topic/172143-change-password-script/#findComment-907658 Share on other sites More sharing options...
ignace Posted August 27, 2009 Share Posted August 27, 2009 UPDATE members SET passwd = $newpasswd WHERE member_id = $id Next time make some effort and read the mysql manual as what you are asking for is simple and is covered in each and every tutorial and php/mysql book. Quote Link to comment https://forums.phpfreaks.com/topic/172143-change-password-script/#findComment-907667 Share on other sites More sharing options...
Russia Posted August 27, 2009 Author Share Posted August 27, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/172143-change-password-script/#findComment-907681 Share on other sites More sharing options...
Russia Posted August 27, 2009 Author Share Posted August 27, 2009 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; } Quote Link to comment https://forums.phpfreaks.com/topic/172143-change-password-script/#findComment-907692 Share on other sites More sharing options...
Russia Posted August 27, 2009 Author Share Posted August 27, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/172143-change-password-script/#findComment-907706 Share on other sites More sharing options...
Russia Posted August 27, 2009 Author Share Posted August 27, 2009 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... Quote Link to comment https://forums.phpfreaks.com/topic/172143-change-password-script/#findComment-907790 Share on other sites More sharing options...
mikesta707 Posted August 27, 2009 Share Posted August 27, 2009 http://www.phpfreaks.com/forums/index.php/topic,200925.0.html Quote Link to comment https://forums.phpfreaks.com/topic/172143-change-password-script/#findComment-907792 Share on other sites More sharing options...
Russia Posted August 27, 2009 Author Share Posted August 27, 2009 That did not help me, what you posted was spam... Quote Link to comment https://forums.phpfreaks.com/topic/172143-change-password-script/#findComment-907813 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.