Jump to content

change paswword function


minneapolis

Recommended Posts

i am trying to add a change password function to a project and i am getting an error. Could somebody take a look at the following code:
[code]

<?php  

//this page lets the a user change their password


//check if the form has been submitted
if (isset($_POST['submitted'])) {

    //connect to the DB
    $dbcn = new mysqli         
            ("localhost","ics325sp0604", "13855",  "ics325sp0604" );
    if(mysqli_connect_errno())    {
              echo "<p>Error creating database connection: </p>";
            exit;
      }

    //create a function for escaping the data

    function escape_data($data) {
        global $dbcn;
        if (ini_get('magic_quotes_gpc')) {
            $data = stripslashes($data);
        }    

            return mysqli_real_escape_string(trim($data), $dbcn);
    }

    $errors = array();

//check for an email address

if (empty($_POST['email'])) {
    $errors[] = 'You forgot to enter your email address';
} else {
    $e = escape_data($_POST['email']);
}

//check for an existing password
if (empty($_POST['password'])) {
    $errors[] = 'You forgot to enter your existing password';
} else {
    $p = escape_data($_POST['password']);
}


if (empty($errors)) {
    //check that they have entered the right email password
    $query = "SELECT username FROM user_info
        WHERE (email = '$e' AND password=SHA('$p'))";
    $result = $dbcn->query($query);
    if (mysqli_num_rows($result) == 1) {
        //get the username
        $row = mysqli_fetch_array($result, MYSQLI_NUM);
        $query = "UPDATE user_info SET password=SHA('$np') WHERE username=$row[0]";
        $result = $dbcn->query($query);
            if (mysqli_affected_rows() == 1) {
                echo 'Thank You! Your password has been updated';
    } else {
        echo 'Your password has not been changed';
    }
}


}


?>
<html>
<head>
<title> Password form</title>
</head>
<body>

<h2>change your password</h2>
    <form action="password.php" method = "post">
        <p>Email address: <input type ="text" name="email" size="20" maxlength="40"
        value="<?php if
        (isset($_POST['email'])) echo $_POST
        ['email']; ?> /> </p>
    
        <p>Current Password: <input type ="password" name="password" size="10" maxlength="20" />
        </p>
                
        <p>New Password: <input type ="password" name="password" size="10" maxlength="20" />
        </p>
                
        <p>Confirm New Password: <input type ="password" name="password" size="10" maxlength="20" />
        </p>    

        <p><input type="submit" name="submit"
        value="Change My Password" /></p>
        <input type="hidden" name="submitted" value="TRUE" />
    </form>

</body>

<html>

  [/code]

The error is the following:


Parse error: parse error, unexpected $ in /home/students/ics325sp06/ics325sp0604/public_html/project4/password.php on line 123
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.