I am developing a simple profile website that allows different users to create a profile and share their profile link so that other can view their profile. I need to use one page to output the profile data instead of creating several pages for each user.
I am using Xampp version 7.3.5-0 runing Apache Server and PHP7. My current profile link is pro/profile/?user=mike, where pro/ is the site URL, profile is a folder containing index.php file to display the user profile and ?user=mike is the query string. Mike in this query string is the username of the current profile to view, if you want to view the profile for another user, say John, you just replace 'mike' with 'john'. Below is a sample query code and error code in index.php file available in the /profile folder:
<?php
require('db_connect.php');
$username=($_GET['user']);
$result=mysqli_query($db_connect,"SELECT * FROM users WHERE
username='$username' LIMIT 1");
$count=mysqli_num_rows($result);
while($row=mysqli_fetch_array($result)){
?>
<?php
if ($count==0) {
echo "Oops! No information was found for $username";
}else{
echo "";
}
?>
Currently if I want to view profiles for three people, say mike, john and hilda, I will use: 1. pro/profile/?user=mike 2. pro/profile/?user=john 3. pro/profile/?user=hilda If I input a user that does not exist, it will display the error message above.
Now I would like to use a different code that will output the user profile without using the GET method, but still using one index.php file instead of creating a folder and a page for each user because there are hundreds of users. The links would change to these: 1. pro/profile/mike 2. pro/profile/john 3. pro/profile/hilda
I don't know if it is possible, please help.