Dylan
Dylan

Reputation: 1

Creating "user pages"

I'm making a very simple web app (for the first time, all this is new to me). I've got a few PHP scripts set up to work with an SQL database to manage user login and registering, but now I want to create something to automatically generate a personal HTML page for a user when they register that displays certain information about them. I'm not sure how to go about doing this.

Upvotes: 0

Views: 127

Answers (3)

AlexJF
AlexJF

Reputation: 886

You would create a PHP script that outputs the user's personal HTML page by checking a username passed to the page by a $_GET variable for example:

$username = $_GET['username']

With this username you can add a WHERE clause to your SQL query (don't forget to mysql_real_escape_string($username) before you do that) and retrieve only the info pertaining to that specific user.

Check mysql_fetch_array for a way to retrieve info from the result of a mysql_query.

And the links to a specific user page would look like this:

http://www.youraddress.com/users.php?username=Dylan

Upvotes: 3

Prisoner
Prisoner

Reputation: 27618

You need to:

  1. Create a webpage such as account.php
  2. Query the database using the usersid which should be stored somewhere like a session or cookie (e.g. SELECT username, dob, gender FROM users WHERE userid = $_SESSION['userid'];) - Don't forget to sanitize userid.
  3. You then need to pull this data from the database, depending on what you're using to query the database (PDO etc) then your method will be different (e.g. using mysql_fetch_assoc, pdo's fetch())
  4. You can then echo the data (e.g. echo $userData['username'])

Upvotes: 4

deceze
deceze

Reputation: 522125

Easiest way:

exmaple.com/user.php?user=123

<?php
    $userId = $_GET['user'];
    $userInfo = // fetch info from database
?>
<h1>User <?php echo $userInfo['username']; ?></h1>
...

Upvotes: 3

Related Questions