insert语句并不是将数据插入到DB中。 但是 if 条件块的代码正在执行。
另外,我收到“int(2)string(27)“未定义的数组键“email””string(52)“C:\ xampp \ htdocs \ DBMS-Project \ Patient erify_user.php”int(65)” verify_user.php 文件中出现错误。
register.php代码
<?php
if(isset($_POST['register'])){
include('../includes/connection.php');
require('C:\xampp\htdocs\DBMS-Project\patient\notification.php');
$email = $_POST['email'];
$mobileNumber = intval($_POST['mobile']); // Convert mobile number to integer
$query = "INSERT into patients values(null, '$_POST[name]', ' $email', '$_POST[password]', $mobileNumber, 'not_verified')";
$query_result = mysqli_query($connection, $query);
if($query_result){
echo "<script type='text/javascript'>
alert('Please verify your email.');
window.location.href = 'verify_user.php';
</script>";
}
else{
echo "<script type='text/javascript'>
alert('Error...Plz try again.');
window.location.href = 'login.php';
</script>";
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login Page</title>
<!-- Bootstrap files -->
<link rel="stylesheet" href="../bootstrap/css//bootstrap.min.css">
<script src="../bootstrap/js/bootstrap.min.js"></script>
<!-- External CSS file -->
<link rel="stylesheet" href="../css/styles.css">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-danger">
<a class="navbar-brand" href="index.php">Blood Donation Bank</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="../index.php">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="../admin/login.php">Admin</a>
</li>
<li class="nav-item">
<a class="nav-link" href="../donor/login.php">Donor</a>
</li>
<li class="nav-item">
<a class="nav-link" href="login.php">Patient</a>
</li>
</ul>
</div>
</nav>
<div class="container-fluid">
<div class="row" style="margin-top: 5%;">
<div class="col-md-4 mx-auto" id="login-container">
<center><h4>Registration Page</h4></center><hr><br>
<form action="verify_user.php" method="POST">
<div class="form-group">
<label for="name">Name:</label>
<input type="text" class="form-control" name="name" placeholder="Enter your name" required>
</div><br>
<div class="form-group">
<label for="email">Email:</label>
<input type="text" class="form-control" name="email" placeholder="Enter email ID" required>
</div><br>
<div class="form-group">
<label for="password">Password:</label>
<input type="password" id="ip2" class="form-control" name="password" placeholder="Enter Password" required>
</div><br>
<div class="form-group">
<label for="mobile">Mobile</label>
<input type="text" class="form-control" name="mobile" placeholder="Mobile No." required>
</div><br>
<input type="submit" class="btn btn-danger" value="Register" name="register">
<strong>Already registered? </strong><a href="login.php">Login here</a>
</form>
</div>
</div>
</div>
</body>
</html>
verify_user.php代码
otp 电子邮件正在发送,但由于上述错误,当我尝试验证电子邮件时,我收到了“无效 otp”错误。
<?php
error_reporting(E_ALL);
ini_set('display_errors', 'On');
set_error_handler("var_dump");
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'C:\xampp\htdocs\DBMS-Project\vendor\autoload.php';
include('../includes/connection.php');
$mail = new PHPMailer(true);
if (isset($_POST['register'])) {
function generateOTP($length = 6) {
return substr(str_shuffle('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'), 0, $length);
}
$otp = generateOTP();
// Establish database connection
$connection = mysqli_connect('localhost', 'root', '', 'bbms');
// Assuming you have a database connection
$email = $_POST['email']; // Get the user's email from the form
$_SESSION['email'] = $email; // Store the email in the session
$storeOtpQuery = "INSERT INTO verification(email, otp) VALUES ('$email', '$otp')";
mysqli_query($connection, $storeOtpQuery);
$message = 'Your OTP is: ' . $otp;
// Read SMTP credentials from secure storage (e.g., config file or environment variables)
$smtpUsername = getenv('SMTP_USERNAME');
$smtpPassword = getenv('SMTP_PASSWORD');
$mail->setFrom('[email protected]', 'Admin');
$mail->addAddress($email);
$mail->Subject = 'Email Verification OTP';
$mail->Body = rawurldecode($message);
$mail->isSMTP();
$mail->Host = 'host90.xhost.co.in';
$mail->SMTPAuth = true;
$mail->Username = '[email protected]';
$mail->Password = '999299292929';
$mail->SMTPSecure = 'ssl'; // Use 'tls' or 'ssl'
$mail->Port = 465; // Adjust the port accordingly
// Handle potential email sending errors
if (!$mail->send()) {
echo 'Email sending failed: ' . $mail->ErrorInfo;
} else {
echo 'Email sent successfully.';
}
}
// OTP Verification Logic
if (isset($_POST['verify'])) {
$enteredOtp = $_POST['otp'];
// Retrieve the email from the session
session_start();
$email = $_SESSION['email'];
$verifyOtpQuery = "SELECT * FROM verification WHERE email = '$email' AND otp = '$enteredOtp'";
$result = mysqli_query($connection, $verifyOtpQuery);
if (mysqli_num_rows($result) > 0) {
// Verification successful
// Update user status in the patients table
$updateStatusQuery = "UPDATE patients SET verification_status = 'verified' WHERE email = '$email'";
mysqli_query($connection, $updateStatusQuery);
// Close database connection
mysqli_close($connection);
if ($updateStatusResult) {
echo "<script type='text/javascript'>
alert('Verification successful.');
window.location.href = 'login.php';
</script>";
} else {
echo "<script type='text/javascript'>
alert('Error updating user status.');
</script>";
}
} else {
// Verification failed
echo "<script type='text/javascript'>
alert('Invalid OTP. Please try again.');
</script>";
}
}
?>
插入语句并没有将数据插入数据库。但是if条件块的代码正在执行 => 在include('../includes/connection.php');中检查Mysql连接是否建立;
另外,我得到“int(2)string(27)“未定义的数组键“email””string(52)“C:\ xampp \ htdocs \ DBMS-Project \ Patient erify_user.php”int(65) “ verify_user.php 文件中出现错误
=>我认为在表单提交时您没有从表单发送电子邮件参数