Your coding example is correct as long as the variable $memberid holds the correct ID number for the current user/member.
In my example the userID is the column name in the database, the $user is a php variable that holds the user/memeber's id.
I am not sure where you are holding the user information once the user has signed in, but in order to have access to this information on every page and eve subsequent requests to the same page you will have to put this information into session or cookie variables. Session variables might make the most sense.
<?php
session_start(); // required for session variables
$_SESSION['memberid'] = $memberid; // Perform after user has successfully logged in
$memberid = $_SESSION['memberid'] // Perform whenever you need access to Member ID
- The session_start function is required to set up a session and access session variables.
- The first statement goes into your login script, after the user has provided a good password. You only need this once and you can use unset($_SESSION['memberid']), to remove the session variables when the user logs off.
- The second statement is used whenever you need to perform any tests based on the memberid. You can access the $_SESSION['memberid'] variable directly, but if you are going to use it more than once it is best to create a local variable.
Reputation Points: 27
Solved Threads: 27
Junior Poster in Training
Offline 88 posts
since Aug 2010