What is the role of PHP in creating a user profile on a website?

PHP plays a crucial role in creating a user profile on a website by handling the backend logic for user registration, login, and profile management. It allows for storing user information in a database, validating user input, and displaying user profiles dynamically on the website.

<?php
// Code to create a user profile in PHP

// Connect to the database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "dbname";
$conn = new mysqli($servername, $username, $password, $dbname);

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

// Insert user profile data into the database
$username = $_POST['username'];
$email = $_POST['email'];
$bio = $_POST['bio'];

$sql = "INSERT INTO user_profiles (username, email, bio) VALUES ('$username', '$email', '$bio')";

if ($conn->query($sql) === TRUE) {
    echo "User profile created successfully";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();
?>