PHP/MySQL userid question?

Shane

New member
Hello,

I am new to PHP and MySQL and need some major help here.

I am creating a website that requires/has multiple tables that I want information interlinking through a userid.

So far, I have been able to get it to post the userid from table a to table b using mysql_insert_id();

However, I am faced with a bigger issue.

I want to create a session of sorts for the userid, so that instantly AFTER successful login it creates a session for ALL the information stored in every table that has userid "x".

Here's what I have as code at the moment.. which I know is wrong, but it allowed me to create sessions for everything else.

PHP:
if(isset($_POST['submit']) && isset($_POST['email']) && isset($_POST['password'])) {

$email = $_POST['email'];
$query = mysql_query("SELECT * FROM users u, accounts a WHERE email = '$email' AND u.userid = a.userid") or die(mysql_error());
$account = mysql_fetch_array($query);

if(md5($_POST['password']) == $user['password']) {

$_SESSION['loggedIn'] = "yes";

$_SESSION['userid'] = $account['userid'];
$_SESSION['firstname'] = $account['firstname'];
$_SESSION['lastname'] = $account['lastname'];
$_SESSION['streetaddress'] = $account['streetaddress'];
$_SESSION['city'] = $account['city'];
$_SESSION['stateprovince'] = $account['stateprovince'];
$_SESSION['zippostalcode'] = $account['zippostalcode'];
$_SESSION['country'] = $account['country'];
$_SESSION['areacode'] = $account['areacode'];
$_SESSION['phonenumber'] = $account['phonenumber'];
$_SESSION['email'] = $account['email'];

$_SESSION['accountname'] = $account['accountname'];
$_SESSION['accounttype'] = $account['accounttype'];
$_SESSION['accountdescription'] = $account['accountdescription'];

}
}

Any syntax errors you may see there is because I didn't copy the whole script.

All the information before ['accountname'] comes from the users table. All information after and including ['accountname'] comes from the accounts table.

I will also be creating a few more tables that will need to be retrieved from the userid.

I can't wrap my head around the logic needed to figure out how to create essentially, an array of all account information from multiple tables just from having the userid as a SESSION when logged in.

Another issue I'm having with the above code is that userid will not post in an echo in the format that I have written out because of it being in several tables makes it "ambiguous."

Can someone please help me with this?

I know it sounds simple but so far to me it really hasn't been.

Much appreciated,
Shane Heyworth

EDIT: Forgot to add some other details. Accounts will essentially be like a commenting system -- in the way that the userid can connect to many different accounts, because users will be able to have unlimited accounts in their user. So that means it has to gather the information from more than one account with the same userid.

Another detail I forgot to mention that in the "main" table -- users -- that the userid is set to auto_increment and is the PRIMARY KEY, but in all other tables it's obviously not -- as it can be posted to several accounts in the account table.
 
Back
Top