What's new

PHP <br /><b>Warning</b>: Undefined array key on line 54

Status
Not open for further replies.

Alieson09

Forum Expert
Joined
Aug 30, 2021
Posts
2,246
Solutions
27
Reaction
2,961
Points
2,085
<br /><b>Warning</b>: Undefined array key on line 54
PHP:
<?php
session_start();
include('includes/header.php');
include('includes/navbar.php');

if (!isset($_SESSION['email'])) {
    header('Location: login.php');
}
$conn = mysqli_connect('localhost', 'root', '', 'bpms2db');
$email = $_SESSION['email'];
$query = "SELECT * FROM login WHERE Email='$email'";
$result = mysqli_query($conn, $query);
$row = mysqli_fetch_assoc($result);
if (isset($_POST['update_profile'])) {
    $email = $_POST['email'];

    $query = "UPDATE login SET Email='$email' WHERE Email='$email'";
    mysqli_query($conn, $query);
    echo "Profile updated successfully";
}
?>

<!DOCTYPE html>
<html lang="en">
                <!-- Begin Page Content -->
    <div class="container-fluid">
                    <!-- Page Heading -->
    <div class="d-sm-flex align-items-center justify-content-between mb-4">
        <h1 class="h3 mb-0 text-gray-800">Admin Profile</h1>
                    </div>
                    <!-- Card Body -->
   <div class="card shadow mb-4">
    <div class="card-header py-3">
    <h6 class="m-0 font-weight-bold text-primary">Profile Page</h6>
        </div>
            <div class="card-body">
    <form method="POST" enctype="multipart/form-data" class="form-horizontal">
            <div class="row form-group">
                <div class="col col-md-3"><label for="text-input" class=" form-control-label">Full Name</label></div>
                <div class="col-12 col-md-9"> <input type="text" name="fullname" required="true" class="form-control" value=""><br></div>
                    </div>
            <div class="row form-group">
                <div class="col col-md-3"><label for="text-input" class=" form-control-label">Address</label></div>
                <div class="col-12 col-md-9"> <input type="text" name="address" required="true" class="form-control" value="">
                </div>
                    </div>
            <div class="row form-group">
                <div class="col col-md-3"><label for="text-input" class=" form-control-label">Contact Number</label></div>
                <div class="col-12 col-md-9"> <input type="text" name="mobilenumber" required="true" class="form-control" value="">
                </div>
                    </div>
            <div class="row form-group">
                <div class="col col-md-3"><label for="text-input" class=" form-control-label">Email Address</label></div>
                <div class="col-12 col-md-9"> <input type="email" name="email" class="form-control" value="<?php echo $row['email']; ?>" required>
                </div>
                    </div>
            <div class="row form-group">
                <div class="col col-md-3"><label for="text-input" class=" form-control-label">Registration</label></div>
                <div class="col-12 col-md-9"> <input type="text" name="regist" required="true" class="form-control" value="" readonly="true">
                </div>
                    </div>
                <p style="text-align: center;"> <button type="submit" class="btn btn-primary btn-sm" name="submit" >Update</button></p>
        </form>
    </div>
</div>
                              
    <!-- Scroll to Top Button-->
    <a class="scroll-to-top rounded" href="#page-top">
        <i class="fas fa-angle-up"></i>
    </a>
</body>
</html>
<?php
include('includes/scripts.php');
?>
 
The "Undefined array key" warning on line 54 is most likely caused by the use of the undefined array key 'email' in the line:

Code:
<div class="col-12 col-md-9"> <input type="email" name="email" class="form-control" value="<?php echo $row['email']; ?>" required>

Looking at the code, it appears that the database column is named Email with a capital "E", but the code is trying to access it with a lowercase "e". To fix the issue, you can change the line to:

Code:
<div class="col-12 col-md-9"> <input type="email" name="email" class="form-control" value="<?php echo $row['Email']; ?>" required>

This will ensure that the correct array key is being used to retrieve the email value from the $row array.
 
Status
Not open for further replies.

Similar threads

Back
Top