Quote (carteblanche @ Oct 19 2016 05:43pm)
our instructor told us we are not using joins for this project as our sql course has not gone over them yet
both the edit profile page and exercise log page both on submit upload it to the database all is workin fine until i try to view it. i am having trouble grabbing data from multiple tables do i have to indivudually select the table and assign the data to variables becauae thats the only non join method i can think of. please help lol maybe i should just use a join although he might not aprove of it.
Code
<?php
session_start();
// If the session vars aren't set, try to set them with a cookie
if (!isset($_SESSION['user_id'])) {
if (isset($_COOKIE['user_id']) && isset($_COOKIE['username'])) {
$_SESSION['user_id'] = $_COOKIE['user_id'];
$_SESSION['username'] = $_COOKIE['username'];
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Mismatch - View Profile</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<h3>Exercise - View Profile</h3>
<?php
require_once('connectvars.php');
// Connect to the database
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
// Make sure the user is logged in before going any further.
if (!isset($_SESSION['user_id'])) {
echo '<p class="login">Please <a href="login.php">log in</a> to access this page.</p>';
exit();
}
else {
echo('<p class="login">You are logged in as ' . $_SESSION['username'] . '. <a href="logout.php">Log out</a>.</p>');
}
// Connect to the database
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
// Grab the profile data from the database
if (!isset($_GET['user_id'])) {
$query = "SELECT username, first_name, last_name, gender, birthdate, weight, FROM exercise_user , exercise_log WHERE user_id = '" . $_SESSION['user_id'] . "'";
}
else {
$query = "SELECT username, first_name, last_name, gender, birthdate, weight, FROM exercise_user , exercise_log WHERE user_id = '" . $_SESSION['user_id'] . "'";
}
$data = mysqli_query($dbc, $query);
if (mysqli_num_rows($data) == 1) {
// The user row was found so display the user data
$row = mysqli_fetch_array($data);
echo '<table>';
if (!empty($row['username'])) {
echo '<tr><td class="label">Username:</td><td>' . $row['username'] . '</td></tr>';
}
if (!empty($row['first_name'])) {
echo '<tr><td class="label">First name:</td><td>' . $row['first_name'] . '</td></tr>';
}
if (!empty($row['last_name'])) {
echo '<tr><td class="label">Last name:</td><td>' . $row['last_name'] . '</td></tr>';
}
if (!empty($row['gender'])) {
echo '<tr><td class="label">Gender:</td><td>';
if ($row['gender'] == 'M') {
echo 'Male';
}
else if ($row['gender'] == 'F') {
echo 'Female';
}
else {
echo '?';
}
echo '</td></tr>';
}
if (!empty($row['birthdate'])) {
if (!isset($_GET['user_id']) || ($_SESSION['user_id'] == $_GET['user_id'])) {
// Show the user their own birthdate
echo '<tr><td class="label">Birthdate:</td><td>' . $row['birthdate'] . '</td></tr>';
}
else {
// Show only the birth year for everyone else
list($year, $month, $day) = explode('-', $row['birthdate']);
echo '<tr><td class="label">Year born:</td><td>' . $year . '</td></tr>';
}
}
if (!empty($row['weight'])) {
echo '<tr><td class="label">weight:</td><td>' . $row['weight'] . '</td></tr>';
}
if (!empty($row['picture'])) {
echo '<tr><td class="label">Picture:</td><td><img src="' . MM_UPLOADPATH . $row['picture'] .
'" alt="Profile Picture" /></td></tr>';
}
echo '</table>';
if (!isset($_GET['user_id']) || ($_SESSION['user_id'] == $_GET['user_id'])) {
echo '<p>Would you like to <a href="editprofile.php">edit your profile</a>?</p>';
}
} // End of check for a single row of user results
else {
echo '<p class="error">There was a problem accessing your profile.</p>';
}
mysqli_close($dbc);
?>
</body>
</html>
This post was edited by jsbb on Oct 19 2016 05:13pm