Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 18
  1. #1

    Problema cambiare password codice PHP!!!

    Ciao sono nuovo del forum e vi espongo il mio problema ho il codice php per cambiare password agli utenti del sito che sto realizzando per un mio amico, ecco il codice PHP con il form per cambiare password, quando si clicca su Change Password invece di cambiare da questo errore

    Warning: mysql_real_escape_string() expects parameter 2 to be resource, null given in D:\Inetpub\webs\feelmeit\databaseconnectinfo.php on line 33

    Warning: mysql_real_escape_string() expects parameter 2 to be resource, null given in D:\Inetpub\webs\feelmeit\databaseconnectinfo.php on line 33

    You forgot to enter your Login Name!

    Please try again.

    Fatal error: Cannot redeclare escape_data() (previously declared in D:\Inetpub\webs\feelmeit\databaseconnectinfo.php:2 8) in D:\Inetpub\webs\feelmeit\manageme.php on line 101

    E dice sempre di provare piu' tardi, al sito sono loggato per cambiare password!!! Cosa sbaglio???

    Ecco il codice PHP con il form il codice php è corretto?

    <?php

    if (isset($_POST['submit'])) {
    // Handle the form.

    require_once ('databaseconnectinfo.php');
    // Connect to the db.

    // Create a function for escaping the data.
    function escape_data ($data) {
    global $dbc; // Need the connection.
    if (ini_get('magic_quotes_gpc')) {
    $data = stripslashes($data);
    }
    return mysql_real_escape_string($data, $dbc);
    }
    // End of function.

    $message = NULL; // Create an empty new variable.

    // Check for a loginName.
    if (empty($_POST['loginName'])) {
    $lo = FALSE;
    $message .= '

    You forgot to enter your Login Name!</p>';
    } else {
    $lo = escape_data($_POST['loginName']);
    }

    // Check for an existing password.
    if (empty($_POST['password'])) {
    $pa = FALSE;
    $message .= '

    You forgot to enter your existing password!</p>';
    } else {
    $pa = escape_data($_POST['password']);
    }

    // Check for a password and match against the confirmed password.
    if (empty($_POST['password1'])) {
    $npa = FALSE;
    $message .= '

    You forgot to enter your new password!</p>';
    } else {
    if ($_POST['password1'] == $_POST['password2']) {
    $npa = escape_data($_POST['password1']);
    } else {
    $npa = FALSE;
    $message .= '

    Your new password did not match the confirmed new password!</p>';
    }
    }

    if ($lo && $pa && $npa) { // If everything's OK.

    $query = "SELECT id FROM tablename WHERE (loginName='$lo' AND password=PASSWORD('$pa') )";
    $result = @mysql_query ($query);
    $num = mysql_num_rows ($result);
    if ($num == 1) {
    $row = mysql_fetch_array($result, MYSQL_NUM);

    // Make the query.
    $query = "UPDATE tablename SET password=PASSWORD('$npa') WHERE id=$row[0]";
    $result = @mysql_query ($query); // Run the query.
    if (mysql_affected_rows() == 1) { // If it ran OK.

    // Send an email, if desired.
    echo '

    Your password has been changed.</p>';

    exit(); // Quit the script.

    } else { // If it did not run OK.
    $message = '

    Your password could not be changed due to a system error. We apologize for any inconvenience.</p>

    ' . mysql_error() . '</p>';
    }
    } else {
    $message = '

    Your loginName and password do not match our records.</p>';
    }
    mysql_close(); // Close the database connection.

    } else {
    $message .= '

    Please try again.</p>';
    }

    } // End of the main Submit conditional.

    // Print the error message if there is one.
    if (isset($message)) {
    echo '<font color="red">', $message, '</font>';
    }
    ?>

    h2>Change Your Password</h2>
    <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">



    Current Password: <input type="password" name="password" size="10" maxlength="20" /></p>


    New Password: <input type="password" name="password1" size="10" maxlength="20" /></p>


    Confirm New Password: <input type="password" name="password2" size="10" maxlength="20" /></p>


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

    Come posso fare per risolvere??? Invece di dire di riprovare piu' tardi vorrei che mi dicesse che la password è stata cambiata!!! Voglio sistemarlo velocemente questo problema e grazie!!!

  2. #2
    Utente di HTML.it
    Registrato dal
    Nov 2008
    Messaggi
    539
    Warning: mysql_real_escape_string() expects parameter 2 to be resource, null given in D:\Inetpub\webs\feelmeit\databaseconnectinfo.php on line 33

    vuol dire che il secondo parametro che passi è nullo anzichè contenere qualcosa....

  3. #3
    Ciao e cosa dovrebbe contenere questo file? databaseconnectinfo.php!!! Ma il codice PHP che ho scritto è corretto???

  4. #4
    Utente di HTML.it L'avatar di dottwatson
    Registrato dal
    Feb 2007
    Messaggi
    3,012
    $dbc deve essere un puntatopre ad una connessione mysql aperta.

    se nel file di connessione fai ad esempio

    $ciccio=mysql_connect(etc etc etc)

    allora quella che viene chiamata $dbc dovrà essere $ciccio


    un riferimento ad una connessione a mysql, appunto

    Non sempre essere l'ultimo è un male... almeno non devi guardarti le spalle

    il mio profilo su PHPClasses e il mio blog laboweb

  5. #5
    Ok e grazie ma in (ecc ecc ecc) cosa ci devo mettere precisamente??? Mi puoi scrivere il codice preciso??? E ciccio sarebbe la tabella che ho creato in MYSQL vero???

  6. #6
    Utente di HTML.it L'avatar di dottwatson
    Registrato dal
    Feb 2007
    Messaggi
    3,012
    conosci php?
    Non sempre essere l'ultimo è un male... almeno non devi guardarti le spalle

    il mio profilo su PHPClasses e il mio blog laboweb

  7. #7
    Ciao hai un PM ti spiego meglio!!!

  8. #8
    Ciao ho questo mysql_connect($db['host'],$db['user'],$db['pass']);
    mysql_select_db($db['name']); e quindi devo mettere praticamente solo db a dbc?

  9. #9
    Ciao ecco l'ho fatto

    <?php

    if (isset($_POST['submit'])) {
    // Handle the form.

    require_once ('manageme.php');
    // Connect to the db.

    // Create a function for escaping the data.
    function escape_data ($data) {
    global $db; // Need the connection.
    if (ini_get('magic_quotes_gpc')) {
    $data = stripslashes($data);
    }
    mysql_connect($db['host'],$db['user'],$db['pass']);
    mysql_select_db($db['name']);;
    }
    // End of function.

    $message = NULL; // Create an empty new variable.

    // Check for a loginName.
    if (empty($_POST['loginName'])) {
    $lo = FALSE;
    $message .= '

    You forgot to enter your Login Name!</p>';
    } else {
    $lo = escape_data($_POST['loginName']);
    }

    // Check for an existing password.
    if (empty($_POST['password'])) {
    $pa = FALSE;
    $message .= '

    You forgot to enter your existing password!</p>';
    } else {
    $pa = escape_data($_POST['password']);
    }

    // Check for a password and match against the confirmed password.
    if (empty($_POST['password1'])) {
    $npa = FALSE;
    $message .= '

    You forgot to enter your new password!</p>';
    } else {
    if ($_POST['password1'] == $_POST['password2']) {
    $npa = escape_data($_POST['password1']);
    } else {
    $npa = FALSE;
    $message .= '

    Your new password did not match the confirmed new password!</p>';
    }
    }

    if ($lo && $pa && $npa) { // If everything's OK.

    $query = "SELECT id FROM tablename WHERE (loginName='".$lo."' AND password=PASSWORD('".$pa."') )";
    $result = mysql_query ($query);
    $num = mysql_num_rows ($result);
    if ($num == 1) {
    $row = mysql_fetch_array($result, MYSQL_NUM);

    // Make the query.
    $query = "UPDATE tablename SET password=PASSWORD('$npa') WHERE id=$row[0]";
    $result = mysql_query ($query); // Run the query.
    if (mysql_affected_rows() == 1) { // If it ran OK.

    // Send an email, if desired.
    echo '

    Your password has been changed.</p>';

    exit(); // Quit the script.

    } else { // If it did not run OK.
    $message = '

    Your password could not be changed due to a system error. We apologize for any inconvenience.</p>

    ' . mysql_error() . '</p>';
    }
    } else {
    $message = '

    Your loginName and password do not match our records.</p>';
    }
    mysql_close(); // Close the database connection.

    } else {
    $message .= '

    Please try again.</p>';
    }

    } // End of the main Submit conditional.

    // Print the error message if there is one.
    if (isset($message)) {
    echo '<font color="red">', $message, '</font>';
    }
    ?>

    Però gli errori non me li da più ma mi da sempre

    You forgot to enter your Login Name!

    Please try again.

    e non mi cambia password cosa manca???

  10. #10
    Ciao ora ho messo al form anche il Login Name ma ora mi da errore solo
    Please Try Again e non m cambia la password come posso fare???

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.