How to make a profile on php

Make a dynamic profile page in php with a simple example: learn how to create a user profile page in php.

Creating a Profile Page in PHP

Creating a profile page in PHP can be a great way to display information about a person or business. The page can be used to display personal information, contact information, a photo, and more. Here is an example of how to create a profile page using PHP.

Step 1: Create the HTML

The first step is to create the HTML for the profile page. We'll start by creating a basic HTML document with a title and meta tags.
<html>
<head>
<title>My Profile Page</title>
<meta charset="utf-8">
</head>
<body>

</body>
</html>
Next, we can add the HTML for the page content. This includes a heading, a photo, and some information about the person or business.
<h1>My Profile</h1>

<img src="profile-photo.jpg">

<p>My name is John Doe and I am a web developer.</p>
<p>I have been working in web development for over 10 years and I specialize in creating custom websites.</p>
<p>I have a Bachelor's degree in Computer Science and I am always looking for ways to improve my skills.</p>

Step 2: Create the PHP

Next, we need to create the PHP code that will retrieve the data from a database and display it on the page. We'll create a simple PHP script that takes the data from a database and displays it on the page.
<?php
$servername = 'localhost';
$username = 'username';
$password = 'password';
$dbname = 'myDB';

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

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

$sql = "SELECT * FROM profiles";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo "<h1>". $row["name"]. "</h1>";
        echo "<img src='". $row["photo"]. "'>";
        echo "<p>". $row["bio"]. "</p>";
    }
} else {
    echo "0 results";
}
$conn->close();
?>

Step 3: Output the HTML and PHP

Finally, we need to output the HTML and PHP code on the page. We can do this by using the echo statement in PHP.
<?php
echo $html;
echo $php;
?>
And with that, we have created a profile page in PHP!

Answers (0)