Jump to content


Photo

I need help with my change user pw script


  • Please log in to reply
7 replies to this topic

#1 unenergizer

unenergizer
  • Members
  • PipPip
  • Member
  • 12 posts
  • LocationUSA

Posted 17 March 2006 - 05:18 AM

<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>


<?

// Includes
include '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';

?>

I would appericate it, if you could help me figure why its not working. Sorry im alittle new to php... :)

thanks,
unenergizer
[a href="http://www.gamehaxs.com" target="_blank"][/a]

#2 Prismatic

Prismatic
  • Members
  • PipPipPip
  • Advanced Member
  • 503 posts
  • LocationSan Diego

Posted 17 March 2006 - 05:33 AM

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 :)

<?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

// Includes
include '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";
    }
}
?>


#3 unenergizer

unenergizer
  • Members
  • PipPip
  • Member
  • 12 posts
  • LocationUSA

Posted 17 March 2006 - 05:39 AM

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
[a href="http://www.gamehaxs.com" target="_blank"][/a]

#4 Prismatic

Prismatic
  • Members
  • PipPipPip
  • Advanced Member
  • 503 posts
  • LocationSan Diego

Posted 17 March 2006 - 05:42 AM

[!--quoteo(post=355832:date=Mar 17 2006, 12:39 AM:name=unenergizer)--][div class=\'quotetop\']QUOTE(unenergizer @ Mar 17 2006, 12:39 AM) View Post[/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 :)


#5 unenergizer

unenergizer
  • Members
  • PipPip
  • Member
  • 12 posts
  • LocationUSA

Posted 17 March 2006 - 05:50 AM

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
[a href="http://www.gamehaxs.com" target="_blank"][/a]

#6 Prismatic

Prismatic
  • Members
  • PipPipPip
  • Advanced Member
  • 503 posts
  • LocationSan Diego

Posted 17 March 2006 - 06:15 AM

[!--quoteo(post=355836:date=Mar 17 2006, 12:50 AM:name=unenergizer)--][div class=\'quotetop\']QUOTE(unenergizer @ Mar 17 2006, 12:50 AM) View Post[/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'];

#7 unenergizer

unenergizer
  • Members
  • PipPip
  • Member
  • 12 posts
  • LocationUSA

Posted 17 March 2006 - 06:40 AM

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
[a href="http://www.gamehaxs.com" target="_blank"][/a]

#8 Prismatic

Prismatic
  • Members
  • PipPipPip
  • Advanced Member
  • 503 posts
  • LocationSan Diego

Posted 17 March 2006 - 06:50 AM

[!--quoteo(post=355853:date=Mar 17 2006, 01:40 AM:name=unenergizer)--][div class=\'quotetop\']QUOTE(unenergizer @ Mar 17 2006, 01:40 AM) View Post[/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!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users