Jump to content

Change password form


graham23s

Recommended Posts

Hi Guys,

 

on my change password form i have an option (a checkbox) for the user to recieve an e-mail aswell (only if they check this box) but they way it is now the e-mail doesn't get sent the code looks ok as far as i can see....

 

changepassword.php

 

<?php
// standard header //
print("<div class=\"subheader\"><div id=\"title\">Home > <span class=\"blue\">Order History</span></div>Change your password below remember to fill in all fields.</div>");

// grab the post data //
if(isset($_POST['submit']))
{
  // vars //
  $old_pass = mysql_real_escape_string(trim($_POST['old_pass']));
  $new_pass = mysql_real_escape_string(trim($_POST['new_pass']));
  $new_pass_again = mysql_real_escape_string(trim($_POST['new_pass_again']));
  
  // session id //
  $var_loggedinuserid = $_SESSION['id'];
  
  // email me var //
  $email_me = $_POST['email_me'];

  // error checking //
  if(empty($old_pass) || empty($new_pass) || empty($new_pass_again))
  {
   display_error("You never filled in all password fields.");
  }
  
  // next see if the users password matched the one we have in mysql //
  $q = "SELECT `password`,`first_name`,`email` FROM `fcp_customers` WHERE `password`='$old_pass' AND `id`='$var_loggedinuserid'";
  $r = mysql_query($q);
  
  // grab some info about the user //
  $row = mysql_fetch_array($r);
  
  // vars //
  $cus_email = $row['email'];
  $cus_first_name = $row['first_name'];

  // results //
  $num_results = mysql_num_rows($r);
  
  // no results back the password is wrong //
  if($num_results <= 0)
  {
   display_error("No match for that password can be found.");  
  }
  
  // does both the new passwords match //
  if($new_pass != $new_pass_again)
  {
   display_error("Your passwords don't match.");    
  }
  
  // if they DO match then update mysql //
  $update = mysql_query("UPDATE `fcp_customers` SET `password`='$new_pass' WHERE `id`='$var_loggedinuserid'");
  
  // display success //
  if($update)
  {
   display_success("Your password has been successfully changed");   
  }
  
   // if the email me button is set send the e-mail //
   if(isset($_POST['email_me']))
   {
     // email string //
     $from = "admin@www.site.co.uk";
     echo $from;
     $to = $cus_email;
     $subject = "www.site.co.uk - Password change";
     $body = "Hi, <b>$cus_first_name</b><br /><br />";
     $body .="Here is a copy of your password change as requested, please keep these details safe.<br /><br />";
     $body .="Your new password is: <b>$new_pass</b><br />";
     $body .="Regards <a href=\"www.site.co.uk\">www.site.co.uk</a>";
     $headers = "MIME-Version: 1.0\r\n";  
     $headers = "From: www.site.co.uk<$from>\n"; 
     $headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; 
     
     // mail code //
     $mail = mail($to,$subject,$body,$headers);   
   
   }
  
} // end isset //

// change the users password form //
print("<form action=\"changepassword.php\" method=\"POST\">\n");
print("<table class=\"login_table\" border=\"1\" cellpadding=\"5\" cellspacing=\"2\">\n");
print("<tr>\n");
print("<td colspan=\"2\" class=\"login_border\" align=\"left\"><b>CHANGE YOUR PASSWORD</b></td>\n");
print("</tr>\n");
print("<tr>\n");
print("<td class=\"login_border\" align=\"right\">Old Password:</td><td class=\"login_border\" align=\"left\"><input type=\"text\" size=\"40\" name=\"old_pass\"/></td>\n");
print("</tr>\n");
print("<tr>\n");
print("<td class=\"login_border\" align=\"right\">New Password:</td><td class=\"login_border\" align=\"left\"><input type=\"password\" size=\"40\" name=\"new_pass\"/></td>\n");
print("</tr>\n");
print("<tr>\n");
print("<td class=\"login_border\" align=\"right\">Confirm New Password:</td><td class=\"login_border\" align=\"left\"><input type=\"password\" size=\"40\" name=\"new_pass_again\"/></td>\n");
print("</tr>");
print("<tr>\n");
print("<td class=\"login_border\" align=\"right\"> </td><td class=\"login_border\" align=\"left\"><input type=\"checkbox\" name=\"email_me\" value='yes'> E-mail me my password details aswell.</td>\n");
print("</tr>");
print("<tr>\n");
print("<td class=\"login_border\" colspan=\"2\" align=\"right\"><input type=\"submit\" name=\"submit\" value=\"Update Password\"></td>\n");
print("</tr>\n");
print("</table><form>\n");
?>

 

 

any help would be appreciated.

 

cheers

 

Graham

Link to comment
Share on other sites

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.