PHP / sql code not running
<p>I am trying to run code that will allow a user to change a password.</p>

<p>I have set up a connection to the database and proved, in the first part, that it is connected - it displays the correct username on the browser.</p>

<p>However when I run the code it displays all ECHO statements, it does NOT generate any email nor does it change the password in the database. Finally, it also gives an error:</p>

<p><strong>Notice: Undefined index: user in C:\xampp\htdocs\mlac2\changepass.php on line 39</strong></p>

<p>I think I am missing something very simple but cannot see what it is</p>

<p>Regards,</p>

<p>'H'</p>

<pre><code>&lt;!DOCTYPE html&gt;
&lt;html&gt;

&lt;head&gt;
&lt;meta content="text/html; charset=utf-8" http-equiv="Content-Type"&gt;
&lt;title&gt;Untitled 1&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;


&lt;h2&gt;Member page for:
&lt;?php

include_once 'header.php';
    echo $_SESSION['user'];

    if (isset($_SESSION['user']))
        {
        $user = sanitizeString($_SESSION['user']);
        $loggedin = TRUE;
        }
    else $loggedin = FALSE;

        echo "&lt;html&gt;&lt;head&gt;&lt;title&gt;$appname";

    if ($loggedin) echo " ($user)";

        echo "&lt;/title&gt;&lt;/head&gt;&lt;body&gt;&lt;font face='verdana' size='2'&gt;";



    if (!isset($_SESSION['user']))
die("&lt;br /&gt;&lt;br /&gt;You must be logged in to view this page");

//This code runs if the form has been submitted
if (isset($_POST['submit']))
if (isset($_POST['submit']))
{
 $email = $_POST['user'];
    $pattern = '/^[^@]+@[^srn;,@%]+$/';
if (!preg_match($pattern, trim($email))) {
  $error[] = 'Please enter a valid email address';
}
// checks if the username is in use
mysql_connect($dbhost, $dbuser, $dbpass) or die(mysql_error());
        mysql_select_db($dbname) or die("Unable to connect: " . mysql_error());
$check = mysql_query("SELECT user FROM password WHERE user='$email'")or die(mysql_error());
$check2 = mysql_num_rows($check);
//if the name exists it gives an error
if ($check2 == 0) {
$error[] = 'Sorry, we cannot find your account details please try another email address.';
}
// if no errors then carry on
if (!$error) {

$query = mysql_query("SELECT user FROM password WHERE user='$email'")or die (mysql_error());
$r = mysql_fetch_object($query);

//create a new random password 
$pass = substr(md5(uniqid(rand(),1)),3,10);
$pass = md5($pass); //encrypted version for database entry

//send email
$to = "$email";
$subject = "Account Details Recovery";
$body = "Hi $email, nn you or someone else have requested your account details. nn Here is your account information please keep this as you may need this at a later stage. nnYour username is $email nn your password is $pass nn Your password has been reset please login and change your password to something more rememberable.nn Regards Site Admin";
$additionalheaders = "From: hamishdoe@btinternet.com";
$additionalheaders .= "Reply-To: hamishdoe@btinternet.com";
mail($to, $subject, $body, $additionalheaders);


//update database
$sql = mysql_query("UPDATE password SET pass='$pass' WHERE user = '$email'")or die (mysql_error());



}// close errors
}// close if form sent 
//show any errors
if (!empty($error))
{
    $i = 0;
    while ($i &lt; count($error)){
    echo "&lt;div class='msg-error'&gt;".$error[$i]."&lt;/div&gt;";
    $i ++;}
}// close if empty errors
 $rsent = true;
if ($rsent == true){
    echo "&lt;p&gt;You have been sent an email with your account details to $user&lt;/p&gt;";
    } else {
    echo "&lt;p&gt;Please enter your e-mail address. You will receive a new password via   e-mail.&lt;/p&gt;";
    } 



?&gt;
    &lt;form action="" method="post"&gt;
&lt;p&gt;Email Address: &lt;input type="text" name="remail" size="50" maxlength="255"&gt;
&lt;input type="submit" name="submit" value="Get New Password"&gt;&lt;/p&gt;
&lt;/form&gt;

&lt;/body&gt;

&lt;/html&gt;
</code></pre>
