Jump to content


change paswword function

  • Please log in to reply
No replies to this topic

#1 minneapolis

  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 16 April 2006 - 09:08 AM

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:


//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>";

    //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';


<title> Password form</title>

<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>New Password: <input type ="password" name="password" size="10" maxlength="20" />
        <p>Confirm New Password: <input type ="password" name="password" size="10" maxlength="20" />

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




The error is the following:

Parse error: parse error, unexpected $ in /home/students/ics325sp06/ics325sp0604/public_html/project4/password.php on line 123

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users