you dont need 2 more fields for MySQL Databases... here is some of my script that i always use
here is for changing the password with an email:
if(isset($_POST['changepassword']))
{
$current = trim($_POST['current']);
$new = trim($_POST['new']);
$confirm = trim($_POST['confirm']);
$pw = md5($current);
$query = mysql_query("SELECT * FROM Users WHERE Password = '$pw' LIMIT 1") or die(mysql_error());
if(mysql_num_rows($query) > 0)
{
while($row = mysql_fetch_array($query))
{
if ( $_POST['new'] == $_POST['confirm'] )
{}else{
echo '<script>alert("Your passwords were not the same, please enter the same password in each field.");</script>';
echo '<script>history.back(1);</script>';
exit;
}
$password = md5($new);
$do = mysql_query("UPDATE Users SET Password = '$password' WHERE Password = '$pw' LIMIT 1") or die(mysql_error());
$dotwo = mysql_query("UPDATE Users SET Activated = 0 WHERE Password = '$password' LIMIT 1") or die(mysql_error());
$send = mail($row['Email'] , "Password changed" , "Your password has been changed to: ".trim($_POST['new'])."\n\nYou can change it again via the members only panel, but first you must re-activate your account:\nhttp://avateinfo.kh3.us/activate.php?id=".$row['Actkey']."\n\nDo not reply to this email, it is automated. Thanks." , "From: noreply@YOURSITE.COM");
if((($do)&&($dotwo)&&($send)))
{
echo '<script>alert("Password changed. You will now be logged out and you must re-activate your account, check your email, a confirmation email has been sent.");</script>';
echo '<script>location.replace("logout.php");</script>';
For Email Change
if(isset($_POST['changeemail']))
{
$current = trim($_POST['current']);
$new = trim($_POST['new']);
$confirm = trim($_POST['confirm']);
$query = mysql_query("SELECT * FROM Users WHERE Email = '$current' LIMIT 1") or die(mysql_error());
if(mysql_num_rows($query) > 0)
{
while($row = mysql_fetch_array($query))
{
if ( $_POST['new'] == $_POST['confirm'] )
{}else{
echo '<script>alert("Your email addresses were not the same, please enter the same email to confirm.");</script>';
echo '<script>history.back(1);</script>';
exit;
}
$do = mysql_query("UPDATE Users SET Email = '$new' WHERE Email = '$current' LIMIT 1") or die(mysql_error());
$dotwo = mysql_query("UPDATE Users SET Activated = 0 WHERE Email = '$new' LIMIT 1") or die(mysql_error());
$send = mail($row['Email'] , "Email changed" , "Your email has been changed to: ".trim($_POST['new'])."\n\nYou can change it again via the members only panel, but first you must re-activate your account:\nhttp://CHANGETHISURL.COM/activate.php?id=".$row['Actkey']."\n\nDo not reply to this email, it is automated. Thanks." , "From: noreply@YOURSITE.COM");
if((($do)&&($dotwo)&&($send)))
{
echo '<script>alert("Email changed. You will now be logged out and you must re-activate your account, check your email, a confirmation email has been sent.");</script>';
echo '<script>location.replace("logout.php");</script>';
FOR ACTIVATING IT:
$id = $_GET['id'];
$query = mysql_query("SELECT * FROM Users WHERE Actkey = '$id' LIMIT 1") or die(mysql_error());
$row = mysql_fetch_array($query);
if(mysql_num_rows($query) > 0){
$user = $row['id'];
$do = mysql_query("UPDATE Users SET Activated = 1 WHERE id = '$user' LIMIT 1") or die(mysql_error());
$send = mail($row['Email'] , "Activation Confirmation" , "Thank you for activating your account, you are now fully registered and able to use our services.\n\nTo login, click the link below:\nhttp://avateinfo.kh3.us/members.avt" , "FROM: noreply@avteinfo.kh3.us");
if(($do)&&($send))
{
echo '<link href="style.css" rel="stylesheet" type="text/css">
<div id="success">
<p>Activation successful! A confirmation email has been dispatched. You can now login!</p>
<p><a href="login.php">Click here</a> to goto the login page.</p>
</div>';
} else {
echo '<link href="style.css" rel="stylesheet" type="text/css">
<div id="error">
<p>We are sorry, there appears to be an error processing your activation. Please try again later.</p>
</div>';
}
} else {
echo '<link href="style.css" rel="stylesheet" type="text/css">
<div id="error">
<p>Sorry, your activation code was incorrect. Please try again.</p>
</div>';
}
mysql_close($l);