Jump to content

Recommended Posts

New at php..

 

If I echo the $member_id it shows the number, but when the form is submitted it doesn't have the session value.  hence an error message that member_id doesn't exist.

 

Thanks,

 

John

 

<?php
session_start();
header ("Cache-control: private");


require_once ('includes/config.inc.php'); 




$member_id = $_SESSION['member_id'];
echo $member_id;
$status = "";


$status = FALSE;

if( isset($_POST['Submit']))  {
	require_once (MYSQL);


if (isset($_POST['status'])){
		$status = $_POST['status'];								
}

} // end if submit

							echo "<form action= 'form2.php'  method='post'>"; 
							echo "<p><h3> Professional Information</h3></p> ";
							echo "<P><b>* Employment Status: </b>";
							echo "<select name='status' id='status'>
									  <option selected='selected'>Select Status</option>
									  <option value='employed'>Employee</option>
									  <option value='BusinessOwner'>Business Owner</option>
									  <option value='Retired'>Retired</option>
								  	</select></p>";
							echo "<p>  <input type='Submit' value='Submit' name='Submit'></p>";
							echo "<input type='hidden' name='submitted' value='TRUE' />";
							//echo "<input type='hidden' name='id' value=' . $id . ' />";

							echo "<p><h6>* required </h6>";
							echo "</form>";


				if ($status ) {

					$q = "INSERT INTO member_work_history (member_id, status, date_created ) VALUES ('$member_id', '$status', NOW() )";
							$r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc));

}

?>

Link to comment
https://forums.phpfreaks.com/topic/145228-session-problem/
Share on other sites

Thanks for the info, still having a problem.

 

The member_id is loaded on the page in a session, but once the form is submitted the session is lost. The error is  Undefined variable: member_id

 

I'm not sure how to code this on the page to have the session remain after the form is submitted.

 

 

Link to comment
https://forums.phpfreaks.com/topic/145228-session-problem/#findComment-762371
Share on other sites

The file above is form2.php

 

<?php

session_start();
header ("Cache-control: private");
require_once ('includes/config.inc.php'); 
require_once (MYSQL);// JD entered this
$url = "";
if (!isset($_SESSION['member_id'])) {
	$url = BASE_URL."forbidden.php";
	header("location: $url");
}

	$sDebug = '';
// Determine member status
if (isset($_SESSION['member_status_id'])) {
	$memberStatus = $_SESSION['member_status_id'];
//		$sDebug = $sDebug."  Status: <i>";
	echo "Status: ".$memberStatus;
	switch($memberStatus) {
		case G_MEMBER_STATUS_ACTIVE:
			if (($userLevel == G_MEMBER_USER_LEVEL_FULL) || ($userLevel == G_MEMBER_USER_LEVEL_ADMIN)) {
				$url = "welcome.php";
				header("location: $url");
			} elseif ($userLevel == G_MEMBER_USER_LEVEL_IC) {
				$url = "home.php";
				header("location: $url");
			}
			break;
		case G_MEMBER_STATUS_APPROVED_FULL:
			$url = "welcome.php";
			header("location: $url");
			break;
		case G_MEMBER_STATUS_APPROVED_IC:
			$url = "welcome.php";
			header("location: $url");
			break;
		case G_MEMBER_STATUS_DECLINED:
			$url = "forbidden.php?r=declined";
			header("location: $url");
			break;
		case G_MEMBER_STATUS_BANNED:
			$url = "forbidden.php?r=banned";
			header("location: $url");
			break;
		case G_IC_MEMBERSHIP_UPGRADE_INVITED_BY_REFERRER:
			$sDebug = $sDebug."IC Membership invited to upgrade by original referrer";
			break;
		case G_IC_MEMBERSHIP_UPGRADE_STEP_2:
			$sDebug = $sDebug."IC Membership registration, step 2 completed";
			break;
		case G_IC_MEMBERSHIP_UPGRADE_STEP_3:
			$sDebug = $sDebug."IC Membership registration, step 3 completed";
			break;
		case G_IC_MEMBERSHIP_UPGRADE_INVITED_BY_OTHER:
			$sDebug = $sDebug."IC Membership invited to upgrade by someone other than original referrer";
			break;
		case G_IC_MEMBERSHIP_UPGRADE_UNDER_REVIEW:
			$sDebug = $sDebug."IC Membership registration complete, under review";
			break;
		case G_MEMBER_STATUS_REGISTRATION_NEW:
			//This member status can not login without a password
			$url = "forbidden.php?r=not%20registered";
			header("location: $url");
			break;
		case G_MEMBER_STATUS_REGISTRATION_STEP_1:
			$sDebug = $sDebug."Full Membership registration, step 1 completed ";
			require_once ("form2.php");			
			break;				
		case G_MEMBER_STATUS_REGISTRATION_STEP_2:
			$sDebug = $sDebug."Full Membership registration, step 2 completed";
			break;
		case G_MEMBER_STATUS_REGISTRATION_STEP_3:
			$sDebug = $sDebug."Full Membership registration, step 3 completed";
			break;
		case G_MEMBER_STATUS_REGISTRATION_UNDER_REVIEW:
			$sDebug = $sDebug."Full Membership registration complete, under review";
			require_once ("status.php");
			break;
		default:
			$url = "forbidden.php?r=undetermined";
			header("location: $url");
	}
	echo "<p>$sDebug</p>";
}
{
		if (G_MEMBER_STATUS_REGISTRATION_STEP_1 )	{
		$q = "SELECT first_name, last_name, email FROM member WHERE member_status_id ='61'";
		$r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc));
		if (mysqli_num_rows($r) != 0) {
		while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
		echo $row['first_name'].' '.$row['last_name'];

		}

}
}
}
?>

Link to comment
https://forums.phpfreaks.com/topic/145228-session-problem/#findComment-762386
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.