<?php
$servername = "localhost";
$username = "s2300379_g5pharmaease";
$password = "12345";
$dbname = "s2300379_g5pharmaease";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// Fetch all records
$sql = "SELECT id, password FROM admin_records";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    while ($row = $result->fetch_assoc()) {
        $id = $row['id'];
        $plainPassword = $row['password']; // Assuming the password is plain text

        // Hash the password
        $hashedPassword = password_hash($plainPassword, PASSWORD_DEFAULT);

        // Update the record with the hashed password
        $updateSql = "UPDATE admin_records SET password = ? WHERE id = ?";
        $stmt = $conn->prepare($updateSql);
        $stmt->bind_param('si', $hashedPassword, $id);
        $stmt->execute();

        echo "Updated password for user ID $id<br>";
    }
} else {
    echo "No records found.";
}

$conn->close();
?>