Jump to content
Larry Ullman's Book Forums

lobo

Members
  • Posts

    1
  • Joined

  • Last visited

Posts posted by lobo

  1. Good day Sir!

    I´ve been working trough the book, script by script, now i can´t keep going because of this error! Can you tell me if there´s something wrong with my script. Maybe I've made a mistake and I can´t see this.

     

    I only get the error "The email address and password do not match those on file." IN RED

    I wrote exactly the script as it is in the book, also with the correction of "$e = ...".

     

    I only translate some texts inside "echo" to portuguese, and I also added <div id="content"></div>.

     

     

     

    <?php # Script 8.7 - password.php

    $page_title = 'Change your password';

    include ('includes/header.html');

     

    ?>

    <div id="content">

    <?php

     

    //this page lets a user change their password

     

    //Check if the form has been submitted:

    if (isset($_POST['submitted'])) {

     

    require_once ('mysqli_connect.php'); // to connect the db.

    $errors = array(); // initialize an error array.

     

    //check for an email adress:

    if (empty($_POST['email'])) {

    $errors[] = 'Não esqueça de informar seu email.';

    } else {

    $e = mysqli_real_escape_string($dbc, trim($_POST['email']));

    }

     

    //check for the current password:

    if (empty($_POST['pass'])) {

    $errors[] = 'Não esqueça de informar sua senha.';

    } else {

    $p = mysqli_real_escape_string($dbc, trim($_POST['pass']));

    }

     

    //check for a new password and match

    //against the confirmed password:

    if (!empty($_POST['pass1'])) {

    if ($_POST['pass1'] != $_POST['pass2']) {

    $errors[] = 'Sua nova senha não confere.';

    } else {

    $np = mysqli_real_escape_string($dbc, trim($_POST['pass1']));

    }

    } else {

    $errors[] = 'Informe sua nova senha.';

    }

     

    if (empty($errors)) { // If everything's ok.

     

    //Check that they've entered the right email adress/password combination:

    $q = "SELECT user_id FROM users WHERE(email='$e' AND pass=SHA1('$p'))";

    $r = @mysqli_query($dbc, $q);

    $num = @mysqli_num_rows($r);

     

    if ($num == 1) { // match was made.

    // Get the user id:

    $row = mysqli_fetch_array($r, MYSQLI_NUM);

     

    // Make the UPDATE query:

    $q = "UPDATE users SET pass=SHA1('$np') WHERE user_id=$row[0]";

    $r = @mysqli_query($dbc, $q);

     

    if (mysqli_affected_rows($dbc) == 1) {//if it ran ok

    // Print a message.

    echo '<h1>Obrigado!</h1>

    <p>Sua senha foi atualizada. Vamos continuar esperando o capítulo 11.</p><p><br/></p>';

     

    } else { // If it did not run OK.

    // Public Message:

    echo '<h1> Erro no Sistema!</h1>

    <p class="error">Sua senha não pode ser atualizada devido a um erro no sistema.</p>';

     

    // Debugging message:

    echo '<p>' . mysqli_error($dbc) . '<br/><br/>Query: ' . $q . '</p>';

    }

     

    // Include the footer and quit the script (to not show the form).

    include ('includes/footer.html');

    exit();

     

    } else { // Invalid email adress password combnation.

    echo '<h1>Erro!</h1>

    <p class="error"> Email ou senha não conferem!</p>';

    }

    } else { //Report the errors.

    echo '<h1>Erro!</h1>

    <p class="error"> Ocorreram os seguintes erros:<br/>';

     

    foreach ($errors as $msg) { // Print each error.

     

    echo " - $msg<br/>\n";

    }

    echo '</p><p> Por favor tente novamente!</p><p><br/></p>';

    } // End of if empty errors

     

    mysqli_close($dbc); // close the connection

     

    } // End of the main submit conditional.

    ?>

    <h1>Trocar Senha</h1>

    <form action="password.php" method="post">

    <p>Email: <input type="text" name="email" size="20" maxlength="60" value="<?php if(isset($_POST['email'])) echo $_POST['email']; ?>"/></p>

    <p>Senha atual: <input type="password" name="pass" size="10" maxlength="20" /></p>

    <p>Senha nova: <input type="password" name="pass1" size="10" maxlength="20" /></p>

    <p>Confirme Nova senha: <input type="password" name="pass2" size="10" maxlength="20" /></p>

    <p><input type="submit" name="submit" value="Trocar Senha"/></p>

    <input type="hidden" name="submitted" value="TRUE" />

    </form>

     

     

    </div>

    <?php

     

    include ('includes/footer.html');

    ?>

     

     

    Thank you for your fast answer. I´m really glad because I chose the right book and the right author.

     

     

     

    __________________________________

     

    Elias Alves

     

    PHP:5.3.1

    MySQL: 5.1.41

    APACHE:2.2.14

×
×
  • Create New...