Thanks Paul.
I just started learning PHP & mySQL, so plese forgive my ignorance. I'm not exactly sure how sessions work, so I sometimes have a hard time explaining what I'm doing.
When the user logs into the system, I create an initial Session that stores the ProfileID.
// connect to database
$link = mysql_connect("localhost", "root", "password") or die("Could not connect. Please try again later.");
mysql_select_db("database",$link) or die("Could not select database. Please try again later.");
//lookup record
/* Perform SQL query : select the userProfile that matches user name and password */
$sql= "SELECT * FROM userProfiles WHERE UserName='$UserName' AND UserPassword='$UserPassword'";
//* return the "result set" (i.e. rows or entries) resulting from the query or return error. */
$result = mysql_query($sql) or die("Error in query result");
$row = mysql_fetch_array($result);
if($row) {
//Get values for User
$type = $row["LoginType"];
$User = $row["UserName"];
$FirstName = $row["FirstName"];
$LastName = $row["LastName"];
$id = $row["ProfileID"];
$val="YES";
// start session
session_start();
$_SESSION['User'] = $User;
$_SESSION['FirstName'] = $FirstName;
$_SESSION['LastName'] = $LastName;
//$_SESSION['CompanyName'] = $CompanyName;
$_SESSION['valid_log'] = array($_SERVER['REMOTE_ADDR'], $User);
Then, from any page when I perform this initial query, I am able to identify the user's ProfileID and CompanyID. Don't ask me how I figured this out, but it works.
$query = "SELECT * FROM userProfiles,companyProfile WHERE userProfiles.CompanyID=companyProfile.CompanyID";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
//Get ID values
if($row) {
$CoID = $row["CompanyID"];
$id = $row["ProfileID"];
}
Print "User ID: $id <br>";
Print "Company ID: $CoID<br>";
So, if I replace my query with either one you suggested and test with the Print command, no ID values are returned! Go figure. Again, I can't explain why.
$query = "SELECT *
FROM userProfiles, companyProfile, employeeProfile
WHERE userProfiles.CompanyID=companyProfile.CompanyID
AND userProfiles.CompanyID=employeeProfile.CompanyID
AND userProfiles.ProfileID = ".$_SESSION['User']." ORDER BY employeeProfile.EmployeeLast, employeeProfile.EmployeeFirst
";
$result2 = mysql_query($query);
$row = mysql_fetch_array($result2);
if($row) {
$CoID = $row["CompanyID"];
$id = $row["ProfileID"];
}
Print "User ID: $id <br>";
Print "Company ID: $CoID<br>";
Please, help me understand!