Ich arbeite an einem PHP-Code, der die Suche nach drei Variablen, $ E-Mail, $ Passwort und $ Adresse verarbeitet. Der Benutzer gibt seine aktuelle E-Mail-Adresse, sein Passwort und eine NEUE Adresse ein, die er im System aktualisieren möchte. [Dies ist das HTML-Formular] [1] Die Abfrage führt diesen Teil der if-Anweisung aus: enter code here
$ body. = "Ungültige E-Mail-Adresse: $ inputemail";PHP Code Fehler Abfrage
Wie sagt es ungültige E-Mail obwohl ich die richtigen Informationen eingegeben habe? Ich bin neu im Codieren, deshalb habe ich Probleme herauszufinden, was das Problem ist. Auch debuggt, ich mit var_dump($db->errorInfo());
und es zurückgegebene Array (size = 3)
0 => string '' (length=0)
1 => null
2 => null
<?php
include_once('support.php');
include_once('connect_database.php');
//connect_database.php contains your connection/creation of a PDO to connect to your MYSQL db on bmgt406.rhsmith.umd.edu/phpmyadmin
ini_set("display_errors","1");
error_reporting(E_ALL);
// Initialize $title and $body.
$title = "Simple Update Request";
$body = "<fieldset><legend>" .$title . "</legend>";
// Initialize variables with values for the name of the table ($name_of_table)
// and the 3 fields - email, password, and address using method GET.
$name_of_table = "requests";
$inputemail = $_GET['email'];
$inputpassword = $_GET['password'];
$address = $_GET['address'];
var_dump($db->errorInfo());
// Check if the table exists in the db
if (tableExists($db, $name_of_table))
{
// Prepare a SQL select query and bind the 3 variables to email, password, and address fields in your database.
$sqlQuery = "SELECT * FROM $name_of_table WHERE email = :email";
$statement1 = $db->prepare($sqlQuery);
$statement1->bindValue(':email', $inputemail, PDO::PARAM_STR);
// Execute the SQL query and store in $result
$result = $statement1->execute();
if (!$result) {
// Retrieving records failed.
$body .= "Retrieving records from table " . $name_of_table . " failed. <br/>";
} else {
// Retrieving records successful.
// Retrieve result into $singleRow using fetch();
$singleRow = $statement1->fetch();
if (!$singleRow){
// Invalid email address has been entered.
$body .= "Invalid email: $inputemail";
} else {
if ($singleRow['password'] != $inputpassword) {
// If the password is not the same as $inputpassword, then an "Invalid Password" has been entered.
$body .= "Invalid password.";
// Get current value from table before UPDATING the user's new address.
} else {
$address = $singleRow['address'];
// Close previous SQl query connection before starting a new query.
$statement1->closeCursor();
// Prepare a SQL Query to update the user information and execute the query.
$sqlQuery = "UPDATE " . $name_of_table . " SET email= :email, password= :password WHERE address= :address";
$statement1 = $db->prepare($sqlQuery);
$statement1->bindValue(':address', $address, PDO::PARAM_STR);
$statement1->bindValue(':email', $inputemail, PDO::PARAM_STR);
$statement1->bindValue(':password', $inputpassword, PDO::PARAM_STR);
// Execute the SQL query and store in $result
$result = $statement1->execute();
// If everything is correct, display the UPDATED user information found (firstname, lastname, address, email, plan)
}
}
$statement1->closeCursor();
}
}
$body .= "<a href=\"index.html\"><input type=\"submit\" value = \"Main Menu\"/></a>";
$body .= "</fieldset>";
echo generatePage($title,$body);
?>
Ihre Abfrage bezieht sich nur auf eine Variable ': email', aber Sie binden': address', ': email' und': password'. –
'WHERE E-Mail =: E-Mail' Sie haben kein Passwort oder eine Adresse. – chris85
** Nie ** speichern Klartext Passwörter. Verwenden Sie stattdessen ['password_hash()'] (http://us3.php.net/manual/en/function.password-hash.php) und ['password_verify()'] (http://us3.php.net /manual/en/function.password-verify.php). Wenn Sie eine Version von PHP vor Version 5.5 verwenden, verwenden Sie ** nicht ** MD5 oder SHA1, um Passwörter zu hashen. Stattdessen können Sie [dieses Kompatibilitätspaket] (https://github.com/ircmaxell/password_compat) verwenden. –