Salve,
Bene io
con l'update di un record in php con estensioni PDO.
Ho questa funzione dove permetto all'utente di recuperare la password(o meglio di reimpostarla a quella di default
Codice PHP:
public function recover() {
// Controllo L'esistenza della coppia Utente/Email
$email = $_POST['email'];
$utente = $_POST['username'];
$sth = $this->db->prepare("SELECT * FROM utenti WHERE
username = :utente AND email = :email");
$sth->execute(array(
':utente' => $utente,
':email' => $email
));
$count = $sth->rowCount();
if ($count == 0) {
header("location: " . BASE_URL . "index/main");
} else {
$postData = array(
'password' => crypto::create(MCRYPT_RIJNDAEL_128, CRYPTO_KEY, DEFAULT_PSW)
);
$where="'username' = '$utente' AND 'email' = '$email'";
$this->db->update('utenti', $postData,$where);
header("location: " . BASE_URL . "index/main");
}
}
Questa è la funzione update di una classe database a cui passo la tabella, i dati da aggiornare e la condizione
Codice PHP:
public function update($table, $data, $where) {
try {
$set = '';
foreach ($data as $key => $value) {
$set.="$key = '$key'";
}
$sql = "UPDATE $table"
. " SET $set"
. " WHERE $where";
session::set('campi', $sql);
$sth = $this->prepare($sql);
foreach ($data as $key => $value) {
$sth->bindValue("':$key'", $value);
}
$sth->execute();
session::set('risultato', $sth->execute());
} catch (PDOException $e) {
echo 'Si è verificata una PDO Exception.';
session::set('risultato', $e->getMessage());
}
}
L'esecuzione mi da come risultato 1 quindi dovrebbe da manuale
Returns TRUE on success or FALSE on failure.
Il problema è che il campo password nella tabella utenti non cambia ..
Qualcuno sa dirmi quale è l'errore ??
Grazie !