I have implemented a log-in routine that I thought captured SESSION variable to use through out all my PHP pages of my site. Here is the snippet of code which sets the session variables:

if($result) {
		if(mysql_num_rows($result) == 1) {
			//Login Successful
			$member = mysql_fetch_assoc($result);
			$_SESSION['SESS_MEMBER_ID'] = $member['id'];
			$_SESSION['SESS_FIRST_NAME'] = $member['First_Name'];
			$_SESSION['SESS_LAST_NAME'] = $member['Last_Name'];
			$_SESSION['SESS_ADMIN'] = $member['ADMIN'];
			header("location: Service_Dates.php");
		}else {
			//Login failed
			header("location: login-failed.php");
	}else {
		die("Query failed");

On one of my pages, I am trying to see if the current logged in user is a volunteer who has already been signed up for a particular Event Date. Here is the code:

  // Check to see if Logged In Volunteer is already in the signed up
$id_User = $_SESSION['SESS_MEMBER_ID'];  
$query2 = "select * FROM Ev_AvVolunteers  where id_Event='$id_Event' and id_Volunteer='$id_User'";
$results2 = mysql_query($query2) or die("Error performing query"); 

if ( $results2 ) { ?>

echo "<div align="left"><span class="style14">Remove Me<br />- <br />";

<? } else { ?>
	echo "<div align="left"><span class="style14">Add Me<br />- <br />";
<? } ?>

Shouldn't this grab my SESSION MEMBER ID?

My goal is to display a "Add Me" or "Remove Me" based on if they exist in the table.

Thanks ;-)

7 Years
Discussion Span
Last Post by diafol

Who is the best (cookies||session) ?

I noticed this thread is solved, but in my opinion, you should use both - depending on your needs. I wouldn't use one instead of the other. If the cookie data is essential to your app, perhaps you could build in some redundancy with sessions in case cookies are turned off by the user. I usually use cookies for 'returning users', like 'remember me' and config settings like language, themes etc. My language switchers usually write changes to cookies, but also write the current language to the session.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.