in this codes i need to add address input in this codes (<?php
// longeva_health_journey/pages/page8.php

// Enable error reporting for debugging (Remove in production)
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

// Start session and include database connection
session_start();
require '../db_connect.php';

// Check if patient_id is set; if not, redirect to page3.php to collect information
if (!isset($_SESSION['patient_id'])) {
    header("Location: page3.php");
    exit();
}

$errors = [];

// Initialize variables
$name = '';
$email = '';
$phone = '';
$gender = '';
$age = '';
$weight = '';
$height = '';
$scheduled_at = '';

// Fetch existing patient_basic_info and consultation date/time to pre-fill the form
try {
    // Fetch patient basic info
    $stmt = $pdo->prepare("SELECT * FROM patient_basic_info WHERE patient_id = ?");
    $stmt->execute([$_SESSION['patient_id']]);
    $basic_info = $stmt->fetch();

    if ($basic_info) {
        $name = htmlspecialchars($basic_info['name']);
        $email = htmlspecialchars($basic_info['email']);
        $phone = htmlspecialchars($basic_info['phone']);
        $gender = htmlspecialchars($basic_info['gender']);
        $age = htmlspecialchars($basic_info['age']);
        $weight = htmlspecialchars($basic_info['weight']);
        $height = htmlspecialchars($basic_info['height']);
    }

    // Fetch existing consultation date and time if available
    $stmt = $pdo->prepare("SELECT scheduled_at FROM patient_consultation WHERE patient_id = ?");
    $stmt->execute([$_SESSION['patient_id']]);
    $consultation = $stmt->fetch();

    if ($consultation) {
        // Ensure the datetime format is compatible with input[type="datetime-local"]
        $scheduled_at = date('Y-m-d\TH:i', strtotime($consultation['scheduled_at']));
    }
} catch (PDOException $e) {
    $errors[] = "Database Error: " . $e->getMessage();
}

// Handle form submission
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    // Collect and sanitize inputs
    $name = isset($_POST['name']) ? htmlspecialchars(trim($_POST['name'])) : '';
    $email = isset($_POST['email']) ? filter_var(trim($_POST['email']), FILTER_SANITIZE_EMAIL) : '';
    $phone = isset($_POST['phone']) ? htmlspecialchars(trim($_POST['phone'])) : '';
    $gender = isset($_POST['gender']) ? htmlspecialchars(trim($_POST['gender'])) : '';
    $age = isset($_POST['age']) ? intval($_POST['age']) : '';
    $weight = isset($_POST['weight']) ? floatval($_POST['weight']) : '';
    $height = isset($_POST['height']) ? floatval($_POST['height']) : '';
    $scheduled_at = isset($_POST['scheduled_at']) ? htmlspecialchars(trim($_POST['scheduled_at'])) : '';

    // Validate inputs
    if (empty($name)) {
        $errors[] = "Name is required.";
    }
    if (empty($email) || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
        $errors[] = "A valid Email is required.";
    }
    if (empty($phone)) {
        $errors[] = "Phone number is required.";
    } elseif (!preg_match('/^[0-9+\-\s()]{7,20}$/', $phone)) {
        $errors[] = "Please enter a valid phone number.";
    }
    if (empty($gender)) {
        $errors[] = "Gender is required.";
    }
    if (empty($age) || $age <= 0) {
        $errors[] = "Valid age is required.";
    }
    if (empty($weight) || $weight <= 0) {
        $errors[] = "Valid weight is required.";
    }
    if (empty($height) || $height <= 0) {
        $errors[] = "Valid height is required.";
    }
    if (empty($scheduled_at)) {
        $errors[] = "Please select a consultation date and time.";
    } else {
        // Validate datetime format
        $date = DateTime::createFromFormat('Y-m-d\TH:i', $scheduled_at);
        if (!$date) {
            $errors[] = "Invalid date and time format.";
        }
    }

    if (empty($errors)) {
        try {
            // Begin transaction to ensure both inserts/updates are successful
            $pdo->beginTransaction();

            // Update or Insert into patient_basic_info
            // Check if patient_basic_info already exists
            $stmt = $pdo->prepare("SELECT patient_id FROM patient_basic_info WHERE patient_id = ?");
            $stmt->execute([$_SESSION['patient_id']]);
            if ($stmt->rowCount() > 0) {
                // Update existing record
                $stmt = $pdo->prepare("UPDATE patient_basic_info SET name = ?, email = ?, phone = ?, gender = ?, age = ?, weight = ?, height = ? WHERE patient_id = ?");
                $stmt->execute([$name, $email, $phone, $gender, $age, $weight, $height, $_SESSION['patient_id']]);
            } else {
                // Insert new record with patient_id
                $stmt = $pdo->prepare("INSERT INTO patient_basic_info (patient_id, name, email, phone, gender, age, weight, height) VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
                $stmt->execute([$_SESSION['patient_id'], $name, $email, $phone, $gender, $age, $weight, $height]);
            }

            // Update or Insert into patient_consultation
            $stmt = $pdo->prepare("SELECT patient_id FROM patient_consultation WHERE patient_id = ?");
            $stmt->execute([$_SESSION['patient_id']]);
            if ($stmt->rowCount() > 0) {
                // Update existing consultation
                $stmt = $pdo->prepare("UPDATE patient_consultation SET scheduled_at = ? WHERE patient_id = ?");
                $stmt->execute([$scheduled_at, $_SESSION['patient_id']]);
            } else {
                // Insert new consultation
                $stmt = $pdo->prepare("INSERT INTO patient_consultation (patient_id, scheduled_at) VALUES (?, ?)");
                $stmt->execute([$_SESSION['patient_id'], $scheduled_at]);
            }

            // Commit transaction
            $pdo->commit();

            // Redirect to page10.php after successful submission
            header("Location: page10.php");
            exit();
        } catch (PDOException $e) {
            // Rollback transaction on error
            $pdo->rollBack();
            $errors[] = "Database Error: " . $e->getMessage();
        }
    }
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Your Information</title>
    <link rel="stylesheet" href="../assets/css/styles.css">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
    <div class="container">
        <div class="header">
            <img src="../assets/images/white-logo.png" alt="Longeva Logo" style="width:25%;">
            <h2>Your Information</h2>
        </div>

        <div class="section">
            <h3>Ensure Your Details Are Correct</h3>
            <p>Providing accurate information helps us serve you better.</p>

            <?php
            if (!empty($errors)) {
                echo '<div class="error">';
                foreach($errors as $error){
                    echo "<p>$error</p>";
                }
                echo '</div>';
            }
            ?>

            <form method="POST" action="">
                <!-- Name -->
                <div class="form-group">
                    <label for="name">Name:</label>
                    <input type="text" id="name" name="name" value="<?php echo htmlspecialchars($name); ?>" required>
                </div>

                <!-- Email -->
                <div class="form-group">
                    <label for="email">Email:</label>
                    <input type="email" id="email" name="email" value="<?php echo htmlspecialchars($email); ?>" required>
                </div>

                <!-- Phone Number -->
                <div class="form-group">
                    <label for="phone">Phone Number:</label>
                    <input type="tel" id="phone" name="phone" value="<?php echo htmlspecialchars($phone); ?>" required>
                </div>

                <!-- Gender -->
                <div class="form-group">
                    <label for="gender">Gender:</label>
                    <select id="gender" name="gender" required>
                        <option value="">--Select Gender--</option>
                        <option value="Male" <?php if($gender == 'Male') echo 'selected'; ?>>Male</option>
                        <option value="Female" <?php if($gender == 'Female') echo 'selected'; ?>>Female</option>
                        <option value="Other" <?php if($gender == 'Other') echo 'selected'; ?>>Other</option>
                    </select>
                </div>

                <!-- Consultation Date and Time -->
                <div class="form-group">
                    <label for="scheduled_at">Select Consultation Date and Time:</label>
                    <input type="datetime-local" id="scheduled_at" name="scheduled_at" value="<?php echo htmlspecialchars($scheduled_at); ?>" required>
                </div>

                <!-- Age -->
                <div class="form-group">
                    <label for="age">Age:</label>
                    <input type="number" id="age" name="age" min="0" value="<?php echo htmlspecialchars($age); ?>" required>
                </div>

                <!-- Weight -->
                <div class="form-group">
                    <label for="weight">Weight (kg):</label>
                    <input type="number" step="0.1" id="weight" name="weight" min="0" value="<?php echo htmlspecialchars($weight); ?>" required>
                </div>

                <!-- Height -->
                <div class="form-group">
                    <label for="height">Height (cm):</label>
                    <input type="number" step="0.1" id="height" name="height" min="0" value="<?php echo htmlspecialchars($height); ?>" required>
                </div>

                <input type="submit" value="Save & Continue">
            </form>
        </div>
    </div>
</body>
</html>) from this codes (<?php
// longeva_health_journey/pages/page8.php

// Enable error reporting for debugging (Remove in production)
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

// Start session and include database connection
session_start();
require '../db_connect.php';

// Check if patient_id is set; if not, redirect to page3.php to collect information
if (!isset($_SESSION['patient_id'])) {
    header("Location: page3.php");
    exit();
}

$errors = [];

// Initialize variables
$gender = '';
$age = '';
$weight = '';
$height = '';
$address = '';
$scheduled_at = '';

// Function to safely escape output
function safe_htmlspecialchars($string) {
    return htmlspecialchars($string ?? '', ENT_QUOTES, 'UTF-8');
}

// Fetch existing patient_basic_info and consultation date/time to pre-fill the form
try {
    // Fetch patient basic info
    $stmt = $pdo->prepare("SELECT gender, age, weight, height, address FROM patient_basic_info WHERE patient_id = ?");
    $stmt->execute([$_SESSION['patient_id']]);
    $basic_info = $stmt->fetch(PDO::FETCH_ASSOC);

    if ($basic_info) {
        $gender = $basic_info['gender'];
        $age = $basic_info['age'];
        $weight = $basic_info['weight'];
        $height = $basic_info['height'];
        $address = $basic_info['address'];
    }

    // Fetch existing consultation date and time if available
    $stmt = $pdo->prepare("SELECT scheduled_at FROM patient_consultation WHERE patient_id = ?");
    $stmt->execute([$_SESSION['patient_id']]);
    $consultation = $stmt->fetch();
    
    if ($consultation) {
        // Ensure the datetime format is compatible with input[type="datetime-local"]
        $scheduled_at = date('Y-m-d\TH:i', strtotime($consultation['scheduled_at']));
    }
} catch (PDOException $e) {
    $errors[] = "Database Error: " . safe_htmlspecialchars($e->getMessage());
}

// Handle form submission
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    // Collect and sanitize inputs
    $gender = isset($_POST['gender']) ? safe_htmlspecialchars(trim($_POST['gender'])) : '';
    $age = isset($_POST['age']) ? intval($_POST['age']) : '';
    $weight = isset($_POST['weight']) ? floatval($_POST['weight']) : '';
    $height = isset($_POST['height']) ? floatval($_POST['height']) : '';
    $address = isset($_POST['address']) ? safe_htmlspecialchars(trim($_POST['address'])) : '';
    $scheduled_at = isset($_POST['scheduled_at']) ? safe_htmlspecialchars(trim($_POST['scheduled_at'])) : '';

    // Validate inputs
    if (empty($gender)) {
        $errors[] = "Gender is required.";
    }
    if (empty($age) || $age <= 0) {
        $errors[] = "Valid age is required.";
    }
    if (empty($weight) || $weight <= 0) {
        $errors[] = "Valid weight is required.";
    }
    if (empty($height) || $height <= 0) {
        $errors[] = "Valid height is required.";
    }
    if (empty($scheduled_at)) {
        $errors[] = "Please select a consultation date and time.";
    } else {
        // Validate datetime format
        $date = DateTime::createFromFormat('Y-m-d\TH:i', $scheduled_at);
        if (!$date) {
            $errors[] = "Invalid date and time format.";
        }
    }

    if (empty($errors)) {
        try {
            // Begin transaction to ensure both updates are successful
            $pdo->beginTransaction();

            // Update or Insert into patient_basic_info
            // Check if patient_basic_info already exists
            $stmt = $pdo->prepare("SELECT patient_id FROM patient_basic_info WHERE patient_id = ?");
            $stmt->execute([$_SESSION['patient_id']]);
            if ($stmt->rowCount() > 0) {
                // Update existing record
                $stmt = $pdo->prepare("UPDATE patient_basic_info SET gender = ?, age = ?, weight = ?, height = ?, address = ? WHERE patient_id = ?");
                $stmt->execute([$gender, $age, $weight, $height, $address, $_SESSION['patient_id']]);
            } else {
                // Insert new record with patient_id
                $stmt = $pdo->prepare("INSERT INTO patient_basic_info (patient_id, gender, age, weight, height, address) VALUES (?, ?, ?, ?, ?, ?)");
                $stmt->execute([$_SESSION['patient_id'], $gender, $age, $weight, $height, $address]);
            }

            // Update or Insert into patient_consultation
            $stmt = $pdo->prepare("SELECT patient_id FROM patient_consultation WHERE patient_id = ?");
            $stmt->execute([$_SESSION['patient_id']]);
            if ($stmt->rowCount() > 0) {
                // Update existing consultation
                $stmt = $pdo->prepare("UPDATE patient_consultation SET scheduled_at = ? WHERE patient_id = ?");
                $stmt->execute([$scheduled_at, $_SESSION['patient_id']]);
            } else {
                // Insert new consultation
                $stmt = $pdo->prepare("INSERT INTO patient_consultation (patient_id, scheduled_at) VALUES (?, ?)");
                $stmt->execute([$_SESSION['patient_id'], $scheduled_at]);
            }

            // Commit transaction
            $pdo->commit();

            // Redirect to page10.php after successful submission
            header("Location: page10.php");
            exit();
        } catch (PDOException $e) {
            // Rollback transaction on error
            $pdo->rollBack();
            // Check if the error is due to foreign key constraint
            if ($e->getCode() == '23000') {
                $errors[] = "Invalid Patient ID. Please ensure the patient exists.";
            } else {
                $errors[] = "Database Error: " . safe_htmlspecialchars($e->getMessage());
            }
        }
    }
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Your Information</title>
    <link rel="stylesheet" href="../assets/css/styles.css">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!-- Optional: Add Bootstrap for better styling -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"/>
</head>
<body>
    <div class="container">
        <div class="header">
            <img src="../assets/images/white-logo.png" alt="Longeva Logo" style="width:25%;">
            <h2>Your Information</h2>
        </div>

        <div class="section">
            <h3>Ensure Your Details Are Correct</h3>
            <p>Providing accurate information helps us serve you better.</p>

            <?php
            if (!empty($errors)) {
                echo '<div class="error alert alert-danger">';
                foreach($errors as $error){
                    echo "<p>" . safe_htmlspecialchars($error) . "</p>";
                }
                echo '</div>';
            }
            ?>

            <form method="POST" action="">
                <!-- Gender -->
                <div class="form-group">
                    <label for="gender">Gender:<span class="text-danger">*</span></label>
                    <select id="gender" name="gender" class="form-control" required>
                        <option value="">--Select Gender--</option>
                        <option value="Male" <?php if($gender == 'Male') echo 'selected'; ?>>Male</option>
                        <option value="Female" <?php if($gender == 'Female') echo 'selected'; ?>>Female</option>
                        <option value="Other" <?php if($gender == 'Other') echo 'selected'; ?>>Other</option>
                    </select>
                </div>

                <!-- Age -->
                <div class="form-group">
                    <label for="age">Age:<span class="text-danger">*</span></label>
                    <input type="number" id="age" name="age" class="form-control" min="0" value="<?php echo safe_htmlspecialchars($age); ?>" required>
                </div>

                <!-- Weight -->
                <div class="form-group">
                    <label for="weight">Weight (kg):<span class="text-danger">*</span></label>
                    <input type="number" step="0.1" id="weight" name="weight" class="form-control" min="0" value="<?php echo safe_htmlspecialchars($weight); ?>" required>
                </div>

                <!-- Height -->
                <div class="form-group">
                    <label for="height">Height (cm):<span class="text-danger">*</span></label>
                    <input type="number" step="0.1" id="height" name="height" class="form-control" min="0" value="<?php echo safe_htmlspecialchars($height); ?>" required>
                </div>

                <!-- Address -->
                <div class="form-group">
                    <label for="address">Address:<span class="text-danger">*</span></label>
                    <textarea id="address" name="address" class="form-control" rows="3" required><?php echo safe_htmlspecialchars($address); ?></textarea>
                </div>

                <!-- Consultation Date and Time -->
                <div class="form-group">
                    <label for="scheduled_at">Select Consultation Date and Time:<span class="text-danger">*</span></label>
                    <input type="datetime-local" id="scheduled_at" name="scheduled_at" class="form-control" value="<?php echo safe_htmlspecialchars($scheduled_at); ?>" required>
                </div>

                <input type="submit" value="Save & Continue" class="btn btn-primary">
            </form>
        </div>
    </div>

    <!-- Optional: Include Bootstrap JS for better interactivity -->
    <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.2/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>) and type full codes