unenergizer Posted March 17, 2006 Share Posted March 17, 2006 [code]<form method="post" action="changepass2.php"><input type="hidden" name="id" value="<?=$id;?>"> <table width="700" border="0" cellpadding="2" cellspacing="1" class="box" align="center"> <tr> <td width="100">New Password</td> <td><input name="newpw" type="text" class="box" id="newpw"></td> </tr> <tr> <td width="100"> </td> <td> </td> </tr> <tr> <td colspan="2" align="center"><input name="update" type="submit" class="box" id="update" value="Update Password"></td> </tr> </table> <p align="center"><a href="memberarea.php">Back to Member Area</a></p></form><?// Includesinclude 'config.php';include 'lang_eng.php';$_SESSION['username'] = $username;$newpw = $_POST[newpw];$md5pw = md5($newpw);$query = "UPDATE sut_users ". "SET password = '$md5pw' ". "WHERE username = '$username'";mysql_query($query) or die('Error : ' . mysql_error());echo 'complete';?> [/code]I would appericate it, if you could help me figure why its not working. Sorry im alittle new to php... :)thanks,unenergizer Quote Link to comment https://forums.phpfreaks.com/topic/5139-i-need-help-with-my-change-user-pw-script/ Share on other sites More sharing options...
Prismatic Posted March 17, 2006 Share Posted March 17, 2006 Whats not working? Whats the error message you are getting?Edit - and I would add a second password field so you can avoid having a user mistype the password they wanted and not being able to log back in.Try this code, should work just fine :)[code]<?php/* Place this at the start of ALL your pages you want to use sessions on */session_start();?><form method="post" action="changepass2.php"><input type="hidden" name="id" value="<?php echo "$id"; ?>"> <table width="700" border="0" cellpadding="2" cellspacing="1" class="box" align="center"> <tr> <td width="100"><div align="right">New Password</div></td> <td><input name="pw1" type="password" class="box" id="newpw"></td> </tr> <tr> <td width="100"><div align="right">Confirm</div></td> <td><input name="pw2" type="password" class="box" id="title"></td> </tr> <tr> <td width="100"> </td> <td> </td> </tr> <tr> <td colspan="2" align="center"><input name="update" type="submit" class="box" id="update" value="Update Password"></td> </tr> </table> <p align="center"><a href="memberarea.php">Back to Member Area</a></p></form><?php// Includesinclude 'config.php';include 'lang_eng.php';$_SESSION['username'] = $username;if($_POST['pw1'] != $_POST['pw2']){ echo "Sorry, the passwords you enterd did not match";}else if(empty($_POST['pw1']) || empty($_POST['pw2'])){ echo "Sorry, you did not enter a password";}else{ $newpw = $_POST['pw1']; $md5pw = md5($newpw); if(mysql_query("UPDATE sut_users SET password = '$md5pw' WHERE username = 'username'")or die('Error : ' . mysql_error())){ echo "Password change successful"; } else{ echo "Error setting new password"; }}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/5139-i-need-help-with-my-change-user-pw-script/#findComment-18259 Share on other sites More sharing options...
unenergizer Posted March 17, 2006 Author Share Posted March 17, 2006 well, im not getting any errors... but its not updating the password... thats what im having a problem with... i might also be having a sessions problem... do any of you know good tutorials for sessions for use with multiple pages?-unenergizer Quote Link to comment https://forums.phpfreaks.com/topic/5139-i-need-help-with-my-change-user-pw-script/#findComment-18260 Share on other sites More sharing options...
Prismatic Posted March 17, 2006 Share Posted March 17, 2006 [!--quoteo(post=355832:date=Mar 17 2006, 12:39 AM:name=unenergizer)--][div class=\'quotetop\']QUOTE(unenergizer @ Mar 17 2006, 12:39 AM) [snapback]355832[/snapback][/div][div class=\'quotemain\'][!--quotec--]well, im not getting any errors... but its not updating the password... thats what im having a problem with... i might also be having a sessions problem... do any of you know good tutorials for sessions for use with multiple pages?-unenergizer[/quote]See the edit in my last post :) Quote Link to comment https://forums.phpfreaks.com/topic/5139-i-need-help-with-my-change-user-pw-script/#findComment-18261 Share on other sites More sharing options...
unenergizer Posted March 17, 2006 Author Share Posted March 17, 2006 Well, i tested it out and when both my passwords are the same, it shows the error pw dont match notice.. also, i have a question about sessions... yes i read the sticky in this forum.. but if i log a userin with my login.php file, how do i get there userid to be a session so i can use it as a varable on other pages?unenergizer Quote Link to comment https://forums.phpfreaks.com/topic/5139-i-need-help-with-my-change-user-pw-script/#findComment-18263 Share on other sites More sharing options...
Prismatic Posted March 17, 2006 Share Posted March 17, 2006 [!--quoteo(post=355836:date=Mar 17 2006, 12:50 AM:name=unenergizer)--][div class=\'quotetop\']QUOTE(unenergizer @ Mar 17 2006, 12:50 AM) [snapback]355836[/snapback][/div][div class=\'quotemain\'][!--quotec--]Well, i tested it out and when both my passwords are the same, it shows the error pw dont match notice.. also, i have a question about sessions... yes i read the sticky in this forum.. but if i log a userin with my login.php file, how do i get there userid to be a session so i can use it as a varable on other pages?unenergizer[/quote]You might have gotten some old code, I updated that code block a few times after I posted it to fix some problems :) It should work fine now :)To use sessions on all pages, put session_start(); at the top of all pages, then, to add a variable to the session do $_SESSION['myvar'] = $myvar;To call it on another page, use session_start(); at the top again, and do $myvar = $_SESSION['myvar']; Quote Link to comment https://forums.phpfreaks.com/topic/5139-i-need-help-with-my-change-user-pw-script/#findComment-18273 Share on other sites More sharing options...
unenergizer Posted March 17, 2006 Author Share Posted March 17, 2006 hey, thanks alot man, you helped fix my problems.. everything is working like a charm now!!! I have one more simple question for you. Would you use Sessions for user level access (like Admin, Mod, User), or would this be a bad idea?thanks agin!!-unenergizer Quote Link to comment https://forums.phpfreaks.com/topic/5139-i-need-help-with-my-change-user-pw-script/#findComment-18277 Share on other sites More sharing options...
Prismatic Posted March 17, 2006 Share Posted March 17, 2006 [!--quoteo(post=355853:date=Mar 17 2006, 01:40 AM:name=unenergizer)--][div class=\'quotetop\']QUOTE(unenergizer @ Mar 17 2006, 01:40 AM) [snapback]355853[/snapback][/div][div class=\'quotemain\'][!--quotec--]hey, thanks alot man, you helped fix my problems.. everything is working like a charm now!!! I have one more simple question for you. Would you use Sessions for user level access (like Admin, Mod, User), or would this be a bad idea?thanks agin!!-unenergizer[/quote]Sessions will work fine, just note that once the user closes their browser, they are logged out, since the sessions only last while the browser is open.Glad I could be of service! Quote Link to comment https://forums.phpfreaks.com/topic/5139-i-need-help-with-my-change-user-pw-script/#findComment-18278 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.