Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Things to notice:
- // The main job of this script is to execute a SELECT statement to find the user's profile information (then display it)
- // execute the header script:
- require_once "header.php";
- if (!isset($_SESSION['loggedInSkeleton']))
- {
- // user isn't logged in, display a message saying they must be:
- echo "You must be logged in to view this page.<br>";
- }
- else
- {
- // user is already logged in, read their username from the session:
- if(isset($_GET['username'])){
- $username = $_SESSION['username'];
- }
- else
- {
- $username=$_SESSION['username'];
- }
- // now read their profile data from the table...
- // connect directly to our database (notice 4th argument):
- $connection = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
- // if the connection fails, we need to know, so allow this exit:
- if (!$connection)
- {
- die("Connection failed: " . $mysqli_connect_error);
- }
- // check for a row in our profiles table with a matching username:
- $query = "SELECT * FROM profiles WHERE username='$username'";
- // this query can return data ($result is an identifier):
- $result = mysqli_query($connection, $query);
- // how many rows came back? (can only be 1 or 0 because username is the primary key in our table):
- $n = mysqli_num_rows($result);
- // if there was a match then extract their profile data:
- if ($n > 0)
- {
- // use the identifier to fetch one row as an associative array (elements named after columns):
- $row = mysqli_fetch_assoc($result);
- // display their profile data:
- echo "First name: {$row['firstname']}<br>";
- echo "Last name: {$row['lastname']}<br>";
- echo "Number of pets: {$row['pets']}<br>";
- echo "Email address: {$row['email']}<br>";
- echo "Date of birth: {$row['dob']}<br>";
- }
- else
- {
- // no match found, prompt user to set up their profile:
- echo "You still need to set up a profile!<br>";
- }
- // we're finished with the database, close the connection:
- mysqli_close($connection);
- }
- // finish off the HTML for this page:
- require_once "footer.php";
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement