$ email, $ password 및 $ address의 세 가지 변수 조회를 처리하는 PHP 코드를 작성하고 있습니다. 사용자는 현재 전자 메일, 암호 및 시스템에서 업데이트하려는 새 주소를 입력합니다. [this is the html form] [1] 쿼리는 if 문의이 부분을 실행합니다. enter code here
$ body. = "잘못된 이메일 : $ inputemail";PHP 코드 오류 쿼리
내가 올바른 정보를 입력했지만 어떻게 잘못된 이메일을 말하는 것입니까? 문제가 무엇인지 파악하는 데 어려움을 겪고 있으므로 코딩에 익숙하지 않습니다. 또한, 나는 var_dump($db->errorInfo());
를 사용하여 디버깅 그리고 배열을 반환 (크기 = 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);
?>
귀하의 검색어는 오직 하나의 변수': email'만을 참조하지만': address',': email' 및': password'를 바인딩합니다. –
'WHERE email = : email' 암호 나 주소가 없습니다. – chris85
** 일반 텍스트 비밀번호는 저장하지 마십시오 **. 대신 ['password_hash()'] (http://us3.php.net/manual/en/function.password-hash.php)와 ['password_verify()'] (http://us3.php.net /manual/en/function.password-verify.php). 5.5 이전 버전의 PHP를 사용하는 경우 MD5 또는 SHA1을 사용하지 말고 암호를 해시하지 마십시오. 대신 [이 호환성 팩] (https://github.com/ircmaxell/password_compat)을 사용할 수 있습니다. –