Я новичок в PHP и все еще учусь, и я столкнулся с этой проблемой при написании страницы PHP, и я думаю, что в строке 65 есть ошибка, я почти уверен, что logi c в порядке. какая-то ошибка в синтаксисе, я думаю, не могли бы вы указать на это для меня
Цель этой страницы - проверить введенный адрес электронной почты, проверить, присутствует ли он в фермерах БД, если он присутствует, он сгенерирует токен и вставит токен в базе данных password_resets, затем отправьте электронное письмо пользователю с токеном в ссылке.
<?php
// Initialize the session
session_start();
// Include config file
require_once "config.php";
// Define variables and initialize with empty values
$email = "";
$email_err = "";
// Processing form data when form is submitted
if($_SERVER["REQUEST_METHOD"] == "POST"){
// Validate new email
if(empty(trim($_POST["email"]))){
$email_err = "Please enter the email.";
} else{
$email = trim($_POST["email"]);
}
$sql = "SELECT email FROM farmers WHERE email = ?";
// Check input errors before updating the database
if($stmt = $mysqli->prepare($sql)){
// Bind variables to the prepared statement as parameters
$stmt->bind_param("s", $param_email);
// Set parameters
$param_email = $email;
// Attempt to execute the prepared statement
if($stmt->execute()){
// Store result
$stmt->store_result();
// Check if email exists
if($stmt->num_rows == 1){
// generate a unique random token of length 100
$token = bin2hex(random_bytes(50));
$sql = "INSERT INTO password_reset(email, token) VALUES (?, ?)";
// Bind result variables
if($stmt = $mysqli->prepare($sql)){
$stmt->bind_param("ss", $param_email, $param_token);
// Set parameters
$param_email = $email;
$param_token = $token;
if($stmt->execute()){
// Send email to user with the token in a link they can click on
$to = $email;
$subject = "Reset your password on site.in";
$msg = "Hi there, click on this <a href=\"pwdreset-farmer.php?token=" . $token . "\">link</a> to reset your password on our site";
$msg = wordwrap($msg,70);
$headers = "From: info@site.in";
mail($to, $subject, $msg, $headers);
header('location: pending.php?email=' . $email);
}
else{
echo "Oops! Something went wrong. Please try again later.";
}
}
else{
echo "Oops! Something went wrong. Please try again later.";
}
}
else{
// Display an error message if email doesn't exist
$email_err = "No account found with that email.";
}
// Close statement
$stmt->close();
}
}
// Close connection
$mysqli->close();
}
?>