title: How to make a change password PHP script work
body: <p>I am a simpleton with less than a cursory knowledge of programming. I have a family web site where we share photos, videos, files and other resources. The site has a simple login feature that begins a session, and I want to be able to provide people with the ability to change their password once logged in.</p>
  
  <p>The database is in MySQL and is extremely simple with only; ID, username, and, password columns (not encrypted or hashed at all). </p>
  
  <p>When it comes to PHP and MySQL I tend to research other people's examples and make them my own, and with the login script I found this very easy to do. However, I have tried and tried and tried to find a PHP snippet that fits with my site and will allow users to change their passwords and have unfortunately failed at every attempt. </p>
  
  <p>I am hoping that someone can assist me in developing what I have already to make it work for my site, any help will be hugely appreciated!</p>
  
  <p>My form simply asks for the logged in user to enter a new password, and then confirm the same password:</p>
  
  <pre><code>    &lt;form name="frmChange" role="form" class="form-signin" method="POST" action="changepword_script.php"&gt;
  
    &lt;div class="form-group"&gt;
  
      &lt;label for="InputPassword2"&gt;New Password&lt;/label&gt;
      &lt;input type="password" class="form-control" id="InputPassword2" placeholder="New Password" name="newPassword"&gt;
       &lt;label for="InputPassword3"&gt;Confirm New Password&lt;/label&gt;
      &lt;input type="password" class="form-control" id="InputPassword3" placeholder="Confirm Password" name="confirmPassword"&gt;  &lt;/div&gt;
     &lt;button class="btn btn-lrg btn-default btn-block" type="submit" value="send"&gt;Change it&lt;/button&gt;
  
  
        &lt;/div&gt;
  
  
        &lt;/form&gt;
  </code></pre>
  
  <p>And my php script (also very simple) just needs to check that the passwords match and then update the database if they do (I have removed the IP address of the database and replaced with zeros):</p>
  
  <pre><code>&lt;?php
  session_start();
  
  if (!(isset($_SESSION['username']) &amp;&amp; $_SESSION['username'] != ''))
  {
      header("location:login.php");
  }
  
  $dbcon = mysql_connect ('000.000.000.00', 'my_db_username', 'my_db_password')
  
  $password1 = $_POST['newPassword'];
  $password2 = $_POST['confirmPassword'];
  
  $password1 = mysql_real_escape_string($password1);
  $password2 = mysql_real_escape_string($password2);
  
  if ($password1 &lt;&gt; $password2){ echo "Your passwords do not match.";}
  {
      echo "your passwords do not match";
  }
  if (mysql_query(UPDATE ebsmembers SET password='$password1' WHERE username='$session[username]'))
  {
      echo "You have successfully changed your password.";
  }
  
  mysql_close($dbcon);
  header("location:login.php");
  
  ?&gt;
  </code></pre>
  
  <p>Again, any help would be massively appreciated as I have really struggled with making this work!</p>
  
  <p>Many thanks,
  Paul</p>