Guest User

Guest User

  • Tech Writer
  • 2.1k
  • 482.6k

Undefined array key otp, email, conn

May 5 2023 3:50 AM

Hi Team

I think i am passing incorrect details from my form to the back end. the fields have current to the table 'password_reset'(id, new_password, confirm_password, otp, created at and timestamp). But now i am getting some undefined array key 'otp, email, conn.

// forgot_password

<div class="container">
  <div class="row justify-content-center">
    <div class="col-md-6">
      <div class="card mt-5">
        <div class="card-header">
          Reset Password
        </div>
        <div class="card-body">
          <form id="forgot-password"  action="otp-confirmation.php" method="POST">
            <div class="form-group">
              <label for="email">Email</label>
              <input type="email" class="form-control" id="email" name="email" required>
            </div>
            <div class="form-group">
              <label for="new-password">New Password</label>
              <input type="password" class="form-control" id="new-password" name="new-password" required>
            </div>
            <div class="form-group">
              <label for="confirm-password">Confirm Password</label>
              <input type="password" class="form-control" id="confirm-password" name="confirm-password" required>
            </div>
            <button type="submit" class="btn btn-primary" name="submit">Reset Password</button>

          </form>
        </div>
      </div>
    </div>
  </div>
</div>

// otp-confirmation.php

<?php
// Start the session
session_start();

require_once(__DIR__ . '/sendEmails/vendor/autoload.php');

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;

// Check if the OTP form is submitted
if (isset($_POST['submit'])) {
    // Check if the OTP entered by the user matches the one stored in the session
    if ($_POST['otp'] == $_SESSION['otp']) {
        // Get the email and new password from the session
        $email = $_SESSION['email'];
        $newPassword = $_SESSION['newPassword'];

        // Include the database connection file
        require_once "dbconn.php";

        // Update the user's password in the database
        // Update the user's password in the database
        $sql = "UPDATE password_reset SET new_password = ? WHERE email = ?";
        $stmt = $conn->prepare($sql);
        $stmt->bind_param("ss", $newPassword, $email);
        $stmt->execute();
        $stmt->close();

// rest of other code below
?>

 


Answers (2)