-2
我一直在試圖建立一個重置密碼功能爲我的網站,用戶可以在其中插入已註冊的電子郵件,這將產生一個隨機OTP以及將存儲在同一列用戶的詳細信息,如使用PHP更新MySQL中特定行中的特定列?
id firstname lastname username email resetpassword
1 name last user email OTP
這是我的代碼,但它不工作。
<?php
require 'dbh.php';
session_start();
$random = mt_rand(1000,1000000);
$email = $_POST['email'];
$sql = "SELECT Email FROM registeredusers WHERE Email='$email'";
$result = mysqli_query($connection,$sql);
$emailCheck = mysqli_num_rows($result);
if (empty($email))
{
echo "please fill out all the fields";
}
else{
$result = mysqli_query($connection,$sql);
$sql = "UPDATE registeredusers SET ResetPassword='$random' WHERE Email='$email'";
Header("Location: submitOTP.php");
}
?>
我只是想這一點,所以形式看起來是這樣的
<form action="resetPassword.php" method="POST">
<input type="text" value="email" name="email"></input>
<input type="submit" value="submit"></input>
</form>
[Little Bobby](http://bobby-tables.com/)說*** [您的腳本存在SQL注入攻擊風險。](http ://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php)***瞭解[prepared](http://en.wikipedia.org/wiki/Prepared_statement) [MySQLi]的聲明(http://php.net/manual/en/mysqli.quickstart.prepared-statements.php)。即使[轉義字符串](http://stackoverflow.com/questions/5741187/sql-injection-that-gets-around-mysql-real-escape-string)是不安全的! [不相信嗎?](http://stackoverflow.com/q/38297105/1011527) –