What are some best practices for creating a dynamic user profile in PHP, especially when adding and deleting profile fields?

When creating a dynamic user profile in PHP, it's important to design a flexible database structure that can easily accommodate adding and deleting profile fields. One approach is to use a separate table to store the profile fields, linking them to the user through a foreign key. This allows for easy addition and removal of fields without altering the main user table.

// Create a table to store profile fields
CREATE TABLE profile_fields (
    id INT AUTO_INCREMENT PRIMARY KEY,
    user_id INT,
    field_name VARCHAR(50),
    field_value VARCHAR(255)
);

// Sample code to add a new profile field for a user
$user_id = 1;
$field_name = 'phone_number';
$field_value = '123-456-7890';

$query = "INSERT INTO profile_fields (user_id, field_name, field_value) VALUES ($user_id, '$field_name', '$field_value')";
// Execute the query to add the new profile field

// Sample code to delete a profile field for a user
$field_id = 1;

$query = "DELETE FROM profile_fields WHERE id = $field_id";
// Execute the query to delete the profile field