Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

$_SESSION shot in the dark 2

Status
Not open for further replies.

jordanking

Programmer
Sep 8, 2005
351
Hello,

this one might be obscure.

I have a user form that accepts user input, evaluates it for errors, and if no errors are found, inserts a record into a mysql database. Everything works perfectly on my testing server (apache) but there is a minor glitch on my remote server.

The problem is:
I use session variables to display a summary of the last successfully inserted record. The php script is sent to itself ($_SERVER['PHP_SELF']) and an array ($error) is created. If there are any errors an array element is added and the insert record script is ignored.

The insert record code is as follows

Code:
// wraps entire insert record behavior in a conditional stament based on whether the $error array is empty
if (!$error) {
	if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "residential")) {
	  $insertSQL = sprintf("INSERT INTO residential (user_id, dt_enter, dt_service, cust_id, service_id, address, city, vendor, `zone`, listers, signs, co_listing, co_value, status, instructions, hanger1, hanger2, hanger3, topper, amount, price) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
						   GetSQLValueString($_POST['user_id'], "int"),
						   GetSQLValueString($_POST['dt_enter'], "date"),
						   GetSQLValueString($_POST['dt_service'], "date"),
						   GetSQLValueString($_POST['realtor_id'], "int"),
						   GetSQLValueString($_POST['service_id'], "int"),
						   GetSQLValueString($_POST['address'], "text"),
						   GetSQLValueString($_POST['city'], "int"),
						   GetSQLValueString($_POST['vendor'], "text"),
						   GetSQLValueString($_POST['zone'], "int"),
						   GetSQLValueString($_POST['listers'], "int"),
						   GetSQLValueString($_POST['signs'], "int"),
						   GetSQLValueString($_POST['co_listing'], "int"),
						   GetSQLValueString($_POST['co_value'], "text"),
						   GetSQLValueString($_POST['status'], "int"),
						   GetSQLValueString($_POST['instructions'], "text"),
						   GetSQLValueString($_POST['hanger1'], "text"),
						   GetSQLValueString($_POST['hanger2'], "text"),
						   GetSQLValueString($_POST['hanger3'], "text"),
						   GetSQLValueString($_POST['topper'], "text"),
						   GetSQLValueString($_POST['amount'], "double"),
						   GetSQLValueString($_POST['price'], "double"));
	
	  mysql_select_db($database_regentAdmin, $regentAdmin);
	  $Result1 = mysql_query($insertSQL, $regentAdmin) or die(mysql_error());
	 
	 // assign a session tracking variable when record is inserted
	 $_SESSION['success'] = $Result1;
			
	  $insertGoTo = "comp_submissions.php";
	  if (isset($_SERVER['QUERY_STRING'])) {
		$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
		$insertGoTo .= $_SERVER['QUERY_STRING'];
	  }
	  header(sprintf("Location: %s", $insertGoTo));
	}
	// if the record has been inserted, clear the POST array
	$_POST = array();
}

The page is based on other session variables so i know that the session is set and working. However the
"$_SESSION['success'] = 1;" is not "working"

later in the script i have a refrence to this value
Code:
		// uses the return value of the insert query function to display a success or error message.
		if(isset($_SESSION['success']) && $_SESSION['success'] == 1){
			echo "<p class='success'><strong>The following record was sucessfully submitted:</strong></p><p class='success'>REALTOR: ".$_SESSION['rltr_firstName']." ".$_SESSION['rltr_familyName']."<br />ADDRESS: ".$_SESSION['address']."</p>";
		}elseif(isset($_SESSION['success']) && $_SESSION['success'] != 1){
	 		echo "<p class='success'>Record submission failed.  Please try again.<br />If problem persits, contact the Regent Signs office.</p>";
		}
it is always unset let alone equal to 1(which is, to my understanding, the successful return of the mysql_query function).

Again, this all works perfectly on my testing apache server.

Is there some session varriable setting that might be different on my remote server that i need to adjust for.

 
what is the value of $_SESSION['success'] after a succesful databse write? check by dumping the $_SESSION variable.

just as an idle thought: in times gone by i had problems with sessions and using redirects. i found that the server was configured to use url rewriting (transid) rather than cookie based sessions. i got around it in one of two ways: (a) dont use header based redirects but make the browser jump using javascript events; or (b) include the SID in the url of the redirected page.
 
Part of your problem is these lines:

$Result1 = mysql_query($insertSQL, $regentAdmin) or die(mysql_error());

// assign a session tracking variable when record is inserted
$_SESSION['success'] = $Result1;

when these lines are run, $_SESSION['success'] will not hold a 1 but rather a boolean TRUE, which may or may not be equivalent to 1, which could throw off the statement:

if(isset($_SESSION['success']) && $_SESSION['success'] == 1){

It could be some kind of weird type-casting problem.



Try replacing:

$_SESSION['success'] = $Result1;

with:
if ($Result1 === TRUE)
$_SESSION['success'] = 1;





Want the best answers? Ask the best questions! TANSTAAFL!
 
thanks for the replys

jrpadie
what is the value of $_SESSION['success'] after a succesful databse write? check by dumping the $_SESSION variable

what do you mean by dumping. IF you mean just "echo" it in the html somewhere, then the value returns 1 on my testing server and nothing on the remote server. On the remote server The session varriable is always empty and/or unset

sleipnir214
Try replacing:

$_SESSION['success'] = $Result1;

with:
if ($Result1 === TRUE)
$_SESSION['success'] = 1;
I tried what you said, but assuemed you meant "$Result1 == TRUE" instead of "$Result1 === TRUE". It still did not work. The records are being inserted correctly. This is the only session variable that does not work.


For further clarification, I just realised all the session variables defined on this page are not working, however, all session varaibles defined on other pages work correctly and are maintained.

I will post my entire code

thanks again
 
I hope this is not too long

but here is my code in full

Code:
<?php require_once('../Connections/regentSelect.php'); ?>
<?php require_once('../Connections/regentAdmin.php'); ?>
<?php
if (!isset($_SESSION)) {
  session_start();
}

//redirect user if thier comp privilages are not yes
if (isset($_SESSION['comp_priv']) && $_SESSION['comp_priv']=='n'){
  $insertGoTo = "indv_submissions.php";
  $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
  header(sprintf("Location: %s", $insertGoTo));
}	

// reset the error tracking array
$error = array();

// recordset retrieves customer information and assigns it to variables
$var1_getCustInfo = "0";
if (isset($_POST['realtor_id'])) {
  $var1_getCustInfo = (get_magic_quotes_gpc()) ? $_POST['realtor_id'] : addslashes($_POST['realtor_id']);
}
mysql_select_db($database_regentAdmin, $regentAdmin);
$query_getCustInfo = sprintf("SELECT customer.idsCustomerID, customer.lngzCompanyID, customer.txtFirstName, customer.txtLastName, customer.lngzAccountStatus, customer.lngzPostID, customer.numHangers, customer.lngzPayment, customer.curSpecial, post.PostId, post.curAddCost FROM customer LEFT JOIN post ON customer.lngzPostID = post.PostID WHERE customer.idsCustomerID = '%s'", $var1_getCustInfo);
$getCustInfo = mysql_query($query_getCustInfo, $regentAdmin) or die(mysql_error());
$row_getCustInfo = mysql_fetch_assoc($getCustInfo);
$totalRows_getCustInfo = mysql_num_rows($getCustInfo);
$rltr_hangers = $row_getCustInfo['numHangers'];
$rltr_payment = $row_getCustInfo['lngzPayment'];
$rltr_special = $row_getCustInfo['curSpecial'];
$rltr_post = $row_getCustInfo['curAddCost'];
$rltr_status = $row_getCustInfo['lngzAccountStatus'];

// Recordset populates the customer drop down menu
$var1_getRealtors = "0";
if (isset($_SESSION['comp_id'])) {
  $var1_getRealtors = (get_magic_quotes_gpc()) ? $_SESSION['comp_id'] : addslashes($_SESSION['comp_id']);
}
mysql_select_db($database_regentSelect, $regentSelect);
$query_getRealtors = sprintf("SELECT customer.idsCustomerID,CONCAT( customer.txtLastName, ', ', customer.txtFirstName) AS Realtor FROM customer WHERE customer.lngzAccountStatus = 1 AND customer.blnErequest = 0 AND customer.lngzCompanyID = %s ORDER BY customer.txtLastName, customer.txtFirstName", $var1_getRealtors);
$getRealtors = mysql_query($query_getRealtors, $regentSelect) or die(mysql_error());
$row_getRealtors = mysql_fetch_assoc($getRealtors);
$totalRows_getRealtors = mysql_num_rows($getRealtors);

// validate form input
$MM_flag="MM_insert";
if (isset($_POST[$MM_flag])) {
	// assign user id value from session variable
	$_POST['user_id'] = intval($_SESSION['user_id']);
	// check to ensure realtor is selected
	if (empty($_POST['realtor_id'])) {
		$error['realtor'] = 'Please select a Realtor for the Record';
	}
	// check to ensure service is selected
	if (empty($_POST['service_id'])) {
		$error['service_blank'] = 'Please select a service for the Record';
	}
	// check to ensure zone is selected
	if (empty($_POST['zone'])) {
		$error['zone_blank'] = 'Please select a zone for the Record';
	}	
	// assign cust_id to a session variable and name
	$_SESSION['rltr_firstName'] = $row_getCustInfo['txtFirstName'];
	$_SESSION['rltr_familyName'] = $row_getCustInfo['txtLastName'];
	$_SESSION['realtor_id'] = $_POST['realtor_id'];
	//check for valid date format
  	$pattern = '((0[1-9]|[12][0-9]|3[01])[/](0[1-9]|1[012])[/](19|20)\d\d)';
	if (!preg_match($pattern, trim($_POST['dt_service']))) {
    	$error['date'] = 'Please enter a valid date. Format: dd/mm/yyyy';
    } else {
		$dt_exp = explode("/", $_POST['dt_service']);
		$d = $dt_exp[0];
		$m = $dt_exp[1];
		$y = $dt_exp[2];
		$_POST['dt_service'] = $y.'-'.$m.'-'.$d;
	} 
	// check to make sure there are no post dated ups or fixes
	$entry_date = trim($_POST['dt_service']);
	$tmrw_date = trim(date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+1, date("y"))));
	if (isset($_POST['service_id']) && $_POST['service_id']==1){
		if ($entry_date != $tmrw_date){
			$error['post_up'] = "Regent Signs does not accept post dated UP requests.  Please change the service date to tommorow.";
		}
	}elseif (isset($_POST['service_id']) && $_POST['service_id']==3){
		if ($entry_date != $tmrw_date){
			$error['post_up'] = "Regent Signs does not accept post dated FIX requests.  Please change the service date to tommorow.";
		}
	}elseif (isset($_POST['service_id']) && $_POST['service_id']==4){
		if ($entry_date != $tmrw_date){
			$error['post_up'] = "Regent Signs does not accept post dated CONDO UP requests.  Please change the service date to tommorow.";
		}	
	}
	// check for valid address format
  	$pattern = '((^([1-9]([0-9]*)[,][\s])(([1-9]([0-9]*))(([-]([1-9]([0-9]*))|([\s][a-z-A-Z\s]*)))))|((^([1-9]([0-9]*))(([-]([1-9]([0-9]*))|([\s][a-z-A-Z\s]*)))))([\s]([a-z-A-Z\s]*)$))';
	if (!preg_match($pattern, trim($_POST['address']))) {
		$error['address'] = 'Please enter a valid Address';
    } 
	$_SESSION['address'] = $_POST['address'];
	// assigne the entry date value
	$_POST['dt_enter'] = date('Y-m-d');	
	// use the service field to assign the status value
	if ($_POST['service_id']==1){
		$_POST['status'] = true;
	}else{
		$_POST['status'] = false;
	}
	// use the service value and city value to calculate the Regent Service value equivilant
	$service_flg = false;
	if ($_POST['service_id']==1 && $service_flg == false){
		if ($_POST['city']<4){
			$_POST['service_id'] = 1;
			$service_flg = true;
		}elseif ($_POST['city']==7){
			$_POST['service_id'] = 3;
			$service_flg = true;
		}elseif ($_POST['city']>3 && $service_flg == false){
			$_POST['service_id'] = 2;
			$service_flg = true;
		}	
	}elseif ($_POST['service_id']==2 && $service_flg == false){
		if ($_POST['city']<4){
			$_POST['service_id'] = 8;
			$service_flg = true;
		}elseif ($_POST['city']==7){
			$_POST['service_id'] = 10;
			$service_flg = true;
		}elseif ($_POST['city']>3 && $service_flg == false){
			$_POST['service_id'] = 9;
			$service_flg = true;
		}
	}elseif ($_POST['service_id']==3 && $service_flg == false){
		if ($_POST['city']<4){
			$_POST['service_id'] = 15;
			$service_flg = true;
		}elseif ($_POST['city']==7){
			$_POST['service_id'] = 17;
			$service_flg = true;
		}elseif ($_POST['city']>3 && $service_flg == false){
			$_POST['service_id'] = 16;
			$service_flg = true;
		}
	}elseif ($_POST['service_id']==4 && $service_flg == false){
		$_POST['service_id'] = 43;
		$service_flg = true;
	}elseif ($_POST['service_id']==5 && $service_flg == false){
		$_POST['service_id'] = 44;
		$service_flg = true;
	}else{
		$error['service'] = 'Invalid Service Codes';
	}
	// recordset for obtaining the service amount
	if (isset($_POST['service_id'])) {
	  $var1_getService = (get_magic_quotes_gpc()) ? $_POST['service_id'] : addslashes($_POST['service_id']);
	}
	mysql_select_db($database_regentAdmin, $regentAdmin);
	$query_getService = sprintf("SELECT service.ServiceId, service.Amount FROM service WHERE service.ServiceId = %s", $var1_getService);
	$getService = mysql_query($query_getService, $regentAdmin) or die(mysql_error());
	$row_getService = mysql_fetch_assoc($getService);
	$totalRows_getService = mysql_num_rows($getService);
	// use the listers value to calculate the co-listing and co_value values
	if ($_POST['listers']>1){
		$_POST['co_listing'] = '1';
		$_POST['co_value'] = "0.5";	
	}else{
		$_POST['co_listing'] = '0';
		$_POST['co_value'] = "";
	}
	// use the customer info table, service, listers, and signs fields to calculate the amount and price values
	// This calculation must occure after the service id has been changed to the Regent Service ID
	if($rltr_status==1){
		if ($rltr_payment==1){
			if ($_POST['service_id'] == (1||2||3)){
				$_POST['amount'] = (($row_getService['Amount']+$rltr_post)/$_POST['listers'])+($rltr_hangers*0.5)+($rltr_special);
				$_POST['price'] = ($_POST['amount']*$_POST['signs']);
			}elseif ($_POST['service_id'] == (8||9||10)){
				$_POST['amount'] = ($row_getService['Amount']/$_POST['listers']);
				$_POST['price'] = ($_POST['amount']*$_POST['signs']);
			}elseif ($_POST['service_id'] == (15||16||17)){
				$_POST['amount'] = ($row_getService['Amount']/$_POST['listers']);
				$_POST['price'] = ($_POST['amount']*$_POST['signs']);
			}elseif ($_POST['service_id'] == (43||44)){
				$_POST['amount'] = ($row_getService['Amount']/$_POST['listers']);
				$_POST['price'] = ($_POST['amount']*$_POST['signs']);
			}else{
				$error['service_amount'] = "There is an error with the service conditions, please contact Regent Signs";
			}
		}elseif($rltr_payment==2){
			if ($_POST['service_id'] == (1||2||3)){
				$_POST['amount'] = ((($row_getService['Amount']+$rltr_post)*2)/$_POST['listers'])+($rltr_hangers*0.5)+($rltr_special);
				$_POST['price'] = ($_POST['amount']*$_POST['signs']);
			}elseif ($_POST['service_id'] == (8||9||10)){
				$_POST['amount'] = 0;
				$_POST['price'] = ($_POST['amount']*$_POST['signs']);
			}elseif ($_POST['service_id'] == (15||16||17)){
				$_POST['amount'] = ($row_getService['Amount']/$_POST['listers']);
				$_POST['price'] = ($_POST['amount']*$_POST['signs']);			
			}elseif ($_POST['service_id'] == (43||44)){
				$_POST['amount'] = ($row_getService['Amount']/$_POST['listers']);
				$_POST['price'] = ($_POST['amount']*$_POST['signs']);
			}else{
				$error['service_amount'] = "There is an error with the service conditions, please contact Regent Signs";
			}
		}else{
			$error['service_value'] = "There is an error with the service calculation, please contact Regent Signs";
		}
	}else{
		$error['status'] = "The selected customer's account has been flagged, please contact Regent Signs";
	}
	// determine whether or not there is a pruchase associated with this listing
	$_POST['purch_id'] = '1';
	// use the city value to place appropriate city code at the beginning of the instructions field 
	if (!$error) {
		if ($_POST['city'] == 2){
			$_POST['instructions'] = 'ShPk ' . $_POST['instructions'];
		}elseif ($_POST['city'] == 3){
			$_POST['instructions'] = 'StAb ' . $_POST['instructions'];
		}elseif ($_POST['city'] == 4){
			$_POST['instructions'] = 'StPl ' . $_POST['instructions'];
		}elseif ($_POST['city'] == 5){
			$_POST['instructions'] = 'SpGr ' . $_POST['instructions'];
		}elseif ($_POST['city'] == 6){
			$_POST['instructions'] = 'Beaumont ' . $_POST['instructions'];
		}elseif ($_POST['city'] == 7){
			$_POST['instructions'] = 'Leduc ' . $_POST['instructions'];
		}elseif ($_POST['city'] == 8){
			$_POST['instructions'] = 'FtSk ' . $_POST['instructions'];
		}elseif ($_POST['city'] == 9){
			$_POST['instructions'] = 'Devon ' . $_POST['instructions'];
		}
	}
	mysql_free_result($getService);
}

function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

// wraps entire insert record behavior in a conditional stament based on whether the $error array is empty
if (!$error) {
	if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "residential")) {
	  $insertSQL = sprintf("INSERT INTO residential (user_id, dt_enter, dt_service, cust_id, service_id, address, city, vendor, `zone`, listers, signs, co_listing, co_value, status, instructions, hanger1, hanger2, hanger3, topper, amount, price) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
						   GetSQLValueString($_POST['user_id'], "int"),
						   GetSQLValueString($_POST['dt_enter'], "date"),
						   GetSQLValueString($_POST['dt_service'], "date"),
						   GetSQLValueString($_POST['realtor_id'], "int"),
						   GetSQLValueString($_POST['service_id'], "int"),
						   GetSQLValueString($_POST['address'], "text"),
						   GetSQLValueString($_POST['city'], "int"),
						   GetSQLValueString($_POST['vendor'], "text"),
						   GetSQLValueString($_POST['zone'], "int"),
						   GetSQLValueString($_POST['listers'], "int"),
						   GetSQLValueString($_POST['signs'], "int"),
						   GetSQLValueString($_POST['co_listing'], "int"),
						   GetSQLValueString($_POST['co_value'], "text"),
						   GetSQLValueString($_POST['status'], "int"),
						   GetSQLValueString($_POST['instructions'], "text"),
						   GetSQLValueString($_POST['hanger1'], "text"),
						   GetSQLValueString($_POST['hanger2'], "text"),
						   GetSQLValueString($_POST['hanger3'], "text"),
						   GetSQLValueString($_POST['topper'], "text"),
						   GetSQLValueString($_POST['amount'], "double"),
						   GetSQLValueString($_POST['price'], "double"));
	
	  mysql_select_db($database_regentAdmin, $regentAdmin);
	  $Result1 = mysql_query($insertSQL, $regentAdmin) or die(mysql_error());
	 
	 // assign a session tracking variable when record is inserted
	 if ($Result1 == TRUE){
          $_SESSION['success'] = 1;
	 }
			
	  $insertGoTo = "comp_submissions.php";
	  if (isset($_SERVER['QUERY_STRING'])) {
		$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
		$insertGoTo .= $_SERVER['QUERY_STRING'];
	  }
	  header(sprintf("Location: %s", $insertGoTo));
	}
	// if the record has been inserted, clear the POST array
	$_POST = array();
}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>E-Request Office Manager Submisions</title>
<link href="../styles/admin_erequest.css" rel="stylesheet" type="text/css" media="screen" />
</head>

<body>
<div id="wrapper">
  <div id="titlebar">
    <div id="tpmenu"> <a href="../index.php">HOME</a>
	<a href="er_menu.php">MENU</a> </div>
  </div>
  <div id="content">
  	<h1>COMPANY E-REQUEST FORM</h1>
	<?php if (!empty($_SESSION['username'])){ echo '<p><span class="radioLabel">Welcome, '.$_SESSION['first_name'].' '.$_SESSION['family_name'].'</span> '; } ?></p>
	<p><span class="radioLabel">DATE:</span> <?php echo date('d/m/Y g:i A'); ?></p>
	<p id="terms">	  Only entries <strong>BEFORE</strong> 1:00 PM will be eligable for &quot;Next Day Service.&quot;</p>
	<?php
		// display alerts that were created during user input validation
		if ($error) {
		  echo '<ul>';
		  foreach ($error as $alert) {
			echo "<li class='warning'>$alert</li>\n";
			}
		  echo '</ul>';
		  }
	?><br />
	<?php
	////*********** testing display vairaible - to be removed before deploying *************** //////////////////////
	echo "<p class='success'><strong>The following record was sucessfully submitted:</strong></p><p class='success'>REALTOR: ".$_SESSION['rltr_firstName']." ".$_SESSION['rltr_familyName']."<br />ADDRESS: ".$_SESSION['address']."</p>";
	if(!empty($_SESSION['success'])){	
		 "<p><strong>TEST VARIABLE: session success = </strong>".$_SESSION['success']."</p>";
	}elseif(empty($_SESSION['success'])){
		 "<p><strong>TEST VARIABLE: session unset = </strong>".$_SESSION['success']."</p>";
	}
	?>
	<?php 
		// uses the return value of the insert query function to display a success or error message.
		if(isset($_SESSION['success']) && $_SESSION['success'] == true){
			echo "<p class='success'><strong>The following record was sucessfully submitted:</strong></p><p class='success'>REALTOR: ".$_SESSION['rltr_firstName']." ".$_SESSION['rltr_familyName']."<br />ADDRESS: ".$_SESSION['address']."</p>";
		}elseif(isset($_SESSION['success']) && $_SESSION['success'] != true){
	 		echo "<p class='success'>Record submission failed.  Please try again.<br />If problem persits, contact the Regent Signs office.</p>";
		}
	 ?>
	<form action="<?php echo $editFormAction; ?>" id="residential" name="residential" method="POST">
       	<p id="terms"> Click on the column heading to recieve help on how to submit your listing. </p>
		<table width="100%" align="center" id="striped">
        <label><tr>
		  <th scope="col"><a href="../help/help.php#help_service_date" target="_blank">Service Date<br />
	      (dd/mm/yyyy)</a></th>
		  <th id="form" scope="col"><a href="../help/help.php#help_realtor" target="_blank">Realtor</a></th>
		  <th scope="col"><a href="../help/help.php#help_service" target="_blank">Service</a></th>
		  <th scope="col"><a href="../help/help.php#help_address" target="_blank">Address</a></th>
		  <th scope="col"><a href="../help/help.php#help_city" target="_blank">City</a></th>
		  <th scope="col"><a href="../help/help.php#help_vendor" target="_blank">Vendor</a></th>
		  <th scope="col"><a href="../help/help.php#help_mls" target="_blank">MLS Zone</a></th>
		  <th scope="col"><a href="../help/help.php#help_listers" target="_blank">Listers</a></th>
		  <th scope="col"><a href="../help/help.php#help_signs" target="_blank">Signs</a></th>
        </tr></label>
        <tr>
          <td><div align="center">
            <input name="dt_service" type="text" id="dt_service" value="<?php $tomorrow = mktime(0, 0, 0, date("m"), date("d")+1, date("y")); echo date('d/m/Y', $tomorrow); ?>" size="15" maxlength="10" />
          </div></td>
          <td><div align="center">
            <select name="realtor_id" class="mediumbox" id="realtor_id">
              <option value=""></option>
              <?php
do {  
?><option value="<?php echo $row_getRealtors['idsCustomerID']?>"<?php if (isset($_POST['realtor_id']) && $_POST['realtor_id']==($row_getRealtors['idsCustomerID'])){echo ' selected="selected"' ;} ?>><?php echo $row_getRealtors['Realtor']?></option>
              <?php
} while ($row_getRealtors = mysql_fetch_assoc($getRealtors));
  $rows = mysql_num_rows($getRealtors);
  if($rows > 0) {
      mysql_data_seek($getRealtors, 0);
	  $row_getRealtors = mysql_fetch_assoc($getRealtors);
  }
?>
            </select>
          </div></td>
          <td>
           	  <div align="center">
           	    <select name="service_id" id="service_id">
				  <option value=""></option>
           	      <option value="1"<?php if (empty($_POST)){ echo ' selected="selected"' ;}elseif (isset($_POST['service_id']) && $_POST['service_id'] == 1 || $_POST['service_id'] == 2 || $_POST['service_id'] == 3){echo ' selected="selected"' ;} ?>>Up</option>
           	      <option value="2"<?php if (empty($_POST)){}elseif (isset($_POST['service_id']) && $_POST['service_id'] == 8 || $_POST['service_id'] == 9 || $_POST['service_id'] == 10){echo ' selected="selected"' ;} ?>>Down</option>
           	      <option value="3"<?php if (empty($_POST)){}elseif (isset($_POST['service_id']) && $_POST['service_id'] == 15 || $_POST['service_id'] == 16 || $_POST['service_id'] == 17){echo ' selected="selected"' ;} ?>>Fix</option>
           	      <option value="4"<?php if (empty($_POST)){}elseif (isset($_POST['service_id']) && $_POST['service_id']==43){echo ' selected="selected"' ;} ?>>Cnd Up</option>
           	      <option value="5"<?php if (empty($_POST)){}elseif (isset($_POST['service_id']) && $_POST['service_id']==44){echo ' selected="selected"' ;} ?>>Cnd Down</option>
       	        </select>
       	    </div></td>
          <td>           	  
		   <div align="center">
            <input value="<?php if (isset($_POST['address'])){
echo $_POST['address'];} ?>" name="address" type="text" id="address" maxlength="30" />
          </div></td>
          <td>
           	  <div align="center">
           	    <select name="city" id="city">
 				  <option value=""></option>
           	      <option value="6"<?php if (isset($_POST['city']) && $_POST['city']==6){echo ' selected="selected"' ;} ?>>Beaumont</option>
           	      <option value="9"<?php if (isset($_POST['city']) && $_POST['city']==9){echo ' selected="selected"' ;} ?>>Devon</option>
           	      <option value="1"<?php if (empty($_POST)){ echo ' selected="selected"' ;}elseif (isset($_POST['city']) && $_POST['city']==1){echo ' selected="selected"' ;} ?>>Edmonton</option>
           	      <option value="8"<?php if (isset($_POST['city']) && $_POST['city']==8){echo ' selected="selected"' ;} ?>>Ft. Saskatchewan</option>
           	      <option value="7"<?php if (isset($_POST['city']) && $_POST['city']==7){echo ' selected="selected"' ;} ?>>Leduc</option>
           	      <option value="2"<?php if (isset($_POST['city']) && $_POST['city']==2){echo ' selected="selected"' ;} ?>>Sherwood Park</option>
           	      <option value="5"<?php if (isset($_POST['city']) && $_POST['city']==5){echo ' selected="selected"' ;} ?>>Spruce Grove</option>
           	      <option value="3"<?php if (isset($_POST['city']) && $_POST['city']==3){echo ' selected="selected"' ;} ?>>St. Albert</option>
           	      <option value="4"<?php if (isset($_POST['city']) && $_POST['city']==4){echo ' selected="selected"' ;} ?>>Stony Plain</option>
       	        </select>
       	    </div></td>
          <td>           	  <div align="center">
            <input value="<?php if (isset($_POST['vendor'])){
echo $_POST['vendor'];} ?>" name="vendor" type="text" id="vendor" maxlength="30" />
          </div></td>
          <td>
           	  <div align="center">
           	    <select name="zone" id="zone">
				  <option value=""></option>
           	      <option value="1"<?php if (isset($_POST['zone']) && $_POST['zone']==1){echo ' selected="selected"' ;} ?>>1 Edm</option>
           	      <option value="2"<?php if (isset($_POST['zone']) && $_POST['zone']==2){echo ' selected="selected"' ;} ?>>2 Edm</option>
           	      <option value="3"<?php if (isset($_POST['zone']) && $_POST['zone']==3){echo ' selected="selected"' ;} ?>>3 Edm</option>
           	      <option value="4"<?php if (isset($_POST['zone']) && $_POST['zone']==4){echo ' selected="selected"' ;} ?>>4 Edm</option>
           	      <option value="5"<?php if (isset($_POST['zone']) && $_POST['zone']==5){echo ' selected="selected"' ;} ?>>5 Edm</option>
           	      <option value="6"<?php if (isset($_POST['zone']) && $_POST['zone']==6){echo ' selected="selected"' ;} ?>>6 Edm</option>
           	      <option value="7"<?php if (isset($_POST['zone']) && $_POST['zone']==7){echo ' selected="selected"' ;} ?>>7 Edm</option>
           	      <option value="8"<?php if (isset($_POST['zone']) && $_POST['zone']==8){echo ' selected="selected"' ;} ?>>8 Edm</option>
           	      <option value="9"<?php if (isset($_POST['zone']) && $_POST['zone']==9){echo ' selected="selected"' ;} ?>>9 Edm</option>
           	      <option value="10"<?php if (isset($_POST['zone']) && $_POST['zone']==10){echo ' selected="selected"' ;} ?>>10 Edm</option>
           	      <option value="11"<?php if (isset($_POST['zone']) && $_POST['zone']==11){echo ' selected="selected"' ;} ?>>11 Edm</option>
           	      <option value="12"<?php if (isset($_POST['zone']) && $_POST['zone']==12){echo ' selected="selected"' ;} ?>>12  Edm</option>
           	      <option value="13"<?php if (isset($_POST['zone']) && $_POST['zone']==13){echo ' selected="selected"' ;} ?>>13 Edm</option>
           	      <option value="14"<?php if (isset($_POST['zone']) && $_POST['zone']==14){echo ' selected="selected"' ;} ?>>14 Edm</option>
           	      <option value="15"<?php if (isset($_POST['zone']) && $_POST['zone']==15){echo ' selected="selected"' ;} ?>>15 Edm</option>
           	      <option value="16"<?php if (isset($_POST['zone']) && $_POST['zone']==16){echo ' selected="selected"' ;} ?>>16 Edm</option>
           	      <option value="17"<?php if (isset($_POST['zone']) && $_POST['zone']==17){echo ' selected="selected"' ;} ?>>17 Edm</option>
           	      <option value="18"<?php if (isset($_POST['zone']) && $_POST['zone']==18){echo ' selected="selected"' ;} ?>>18 Edm</option>
           	      <option value="19"<?php if (isset($_POST['zone']) && $_POST['zone']==19){echo ' selected="selected"' ;} ?>>19 Edm</option>
           	      <option value="20"<?php if (isset($_POST['zone']) && $_POST['zone']==20){echo ' selected="selected"' ;} ?>>20 Edm</option>
           	      <option value="21"<?php if (isset($_POST['zone']) && $_POST['zone']==21){echo ' selected="selected"' ;} ?>>21 Edm</option>
           	      <option value="22"<?php if (isset($_POST['zone']) && $_POST['zone']==22){echo ' selected="selected"' ;} ?>>22 Edm</option>
           	      <option value="23"<?php if (isset($_POST['zone']) && $_POST['zone']==23){echo ' selected="selected"' ;} ?>>23 Edm</option>
           	      <option value="24"<?php if (isset($_POST['zone']) && $_POST['zone']==24){echo ' selected="selected"' ;} ?>>24 St. Albert</option>
           	      <option value="25"<?php if (isset($_POST['zone']) && $_POST['zone']==25){echo ' selected="selected"' ;} ?>>25 Sher Park</option>
           	      <option value="26"<?php if (isset($_POST['zone']) && $_POST['zone']==26){echo ' selected="selected"' ;} ?>>26 Edm</option>
           	      <option value="27"<?php if (isset($_POST['zone']) && $_POST['zone']==27){echo ' selected="selected"' ;} ?>>27 Edm</option>
           	      <option value="28"<?php if (isset($_POST['zone']) && $_POST['zone']==28){echo ' selected="selected"' ;} ?>>28 Edm</option>
           	      <option value="29"<?php if (isset($_POST['zone']) && $_POST['zone']==29){echo ' selected="selected"' ;} ?>>29 Edm</option>
           	      <option value="30"<?php if (isset($_POST['zone']) && $_POST['zone']==30){echo ' selected="selected"' ;} ?>>30 Edm</option>
           	      <option value="35"<?php if (isset($_POST['zone']) && $_POST['zone']==35){echo ' selected="selected"' ;} ?>>35 Edm</option>
           	      <option value="40"<?php if (isset($_POST['zone']) && $_POST['zone']==40){echo ' selected="selected"' ;} ?>>40 Edm</option>
           	      <option value="41"<?php if (isset($_POST['zone']) && $_POST['zone']==41){echo ' selected="selected"' ;} ?>>41 Edm</option>
           	      <option value="42"<?php if (isset($_POST['zone']) && $_POST['zone']==42){echo ' selected="selected"' ;} ?>>42 Edm</option>
           	      <option value="50"<?php if (isset($_POST['zone']) && $_POST['zone']==50){echo ' selected="selected"' ;} ?>>50 Edm</option>
           	      <option value="51"<?php if (isset($_POST['zone']) && $_POST['zone']==51){echo ' selected="selected"' ;} ?>>51 Edm</option>
           	      <option value="52"<?php if (isset($_POST['zone']) && $_POST['zone']==52){echo ' selected="selected"' ;} ?>>52 Edm</option>
           	      <option value="53"<?php if (isset($_POST['zone']) && $_POST['zone']==53){echo ' selected="selected"' ;} ?>>53 Edm</option>
           	      <option value="54"<?php if (isset($_POST['zone']) && $_POST['zone']==54){echo ' selected="selected"' ;} ?>>54 Edm</option>
           	      <option value="55"<?php if (isset($_POST['zone']) && $_POST['zone']==55){echo ' selected="selected"' ;} ?>>55 Edm</option>
           	      <option value="56"<?php if (isset($_POST['zone']) && $_POST['zone']==56){echo ' selected="selected"' ;} ?>>56 Edm</option>
           	      <option value="57"<?php if (isset($_POST['zone']) && $_POST['zone']==57){echo ' selected="selected"' ;} ?>>57 Edm</option>
           	      <option value="58"<?php if (isset($_POST['zone']) && $_POST['zone']==58){echo ' selected="selected"' ;} ?>>58 Edm</option>
           	      <option value="59"<?php if (isset($_POST['zone']) && $_POST['zone']==59){echo ' selected="selected"' ;} ?>>59 Edm</option>
           	      <option value="62"<?php if (isset($_POST['zone']) && $_POST['zone']==62){echo ' selected="selected"' ;} ?>>62 Ft. Sask</option>
           	      <option value="81"<?php if (isset($_POST['zone']) && $_POST['zone']==81){echo ' selected="selected"' ;} ?>>81 Leduc</option>
           	      <option value="82"<?php if (isset($_POST['zone']) && $_POST['zone']==82){echo ' selected="selected"' ;} ?>>82 Beaumont</option>
           	      <option value="91"<?php if (isset($_POST['zone']) && $_POST['zone']==91){echo ' selected="selected"' ;} ?>>91 Sp. Grove</option>
           	      <option value="91"<?php if (isset($_POST['zone']) && $_POST['zone']==91){echo ' selected="selected"' ;} ?>>91 St. Plain</option>
           	      <option value="92"<?php if (isset($_POST['zone']) && $_POST['zone']==92){echo ' selected="selected"' ;} ?>>92 Devon</option>
       	        </select>
       	    </div></td>
          <td>           	  <div align="center">
            <input name="listers" type="text" id="listers" value="<?php if (isset($_POST['listers'])){
echo $_POST['listers'];}else{ echo '1'; } ?>" size="4" maxlength="1" />
          </div></td>
          <td>           	  <div align="center">
            <input name="signs" type="text" id="signs" value="<?php if (isset($_POST['signs'])){
echo $_POST['signs'];}else{ echo '1'; } ?>" size="4" />
          </div></td>
        </tr>
      </table>
	  <p><label>Instructions:</label><input value="<?php if (isset($_POST['instructions'])){
echo $_POST['instructions'];} ?>" name="instructions" type="text" class="widebox" id="instructions" maxlength="60" />
	  </p>
	  <p>
	    <label>Hanger 1:
	    <input value="<?php if (isset($_POST['hanger1'])){
echo $_POST['hanger1'];} ?>" name="hanger1" type="text" class="mediumbox" id="hanger1" />
	    </label>
	    <label>Hanger 2:
	    <input value="<?php if (isset($_POST['hanger2'])){
echo $_POST['hanger2'];} ?>" name="hanger2" type="text" class="mediumbox" id="hanger2" />
	    </label>
	    <label>Hanger 3:
	    <input value="<?php if (isset($_POST['hanger3'])){
echo $_POST['hanger3'];} ?>" name="hanger3" type="text" class="mediumbox" id="hanger3" />
	    </label>
	  </p>
	  <p>
	    <label>Topper:
	    <input value="<?php if (isset($_POST['topper'])){
echo $_POST['topper'];} ?>" name="topper" type="text" class="mediumbox" id="topper" />
	    </label>
	    <label></label>
	  </p>
	  <p>
        <input name="insert" type="submit" id="insert" value="Insert Record" />
      
	    <input name="co_value" type="hidden" id="co_value" />
        <input name="co_listing" type="hidden" id="co_listing" />
        <input name="status" type="hidden" id="status" />
        <input name="amount" type="hidden" id="amount" />
        <input name="price" type="hidden" id="price" />
        <input name="user_id" type="hidden" id="user_id" value="<?php echo $_SESSION['user_id']; ?>" />
        <input name="dt_enter" type="hidden" id="dt_enter" />
</p>
      
      <input type="hidden" name="MM_insert" value="residential">
    </form>
    <p>Click    	      <?php if ($_SESSION['comp_priv']=='y'){
		  	 echo "<a href='comp_daily_log.php'>HERE</a>";
		  }else{
		     echo "<a href='indv_daily_log.php'>HERE</a>";
		  }
		  ?> to see a list of all confirmed entries for today </p>
	<p>&nbsp;</p>
	<p><span class="radioLabel"><a href="../help/help.php#help_terms">REVIEW</a> THE REGENT SIGNS E-REQUEST TERMS AND CONDITIONS: </span></p>
  </div>
</div>
</body>
</html>
<?php
mysql_free_result($getRealtors);

mysql_free_result($getCustInfo);

?>
 
No, I meant "===".

But you have:

$_SESSION['success'] = 1;

And then later:

if(isset($_SESSION['success']) && $_SESSION['success'] == true){

Either set the session variable to 1 and test for 1 or set the variable to TRUE and test for TRUE.

How, exactly, have you determined that session variables are not working in this script?



Want the best answers? Ask the best questions! TANSTAAFL!
 
thanks sleipnir214,

you are right, I fixed the conditional stament to set the session varriable to 1 if the mysql_query function returns true. As follows

Code:
	 if ($Result1 === TRUE){
          $_SESSION['success'] = 1;
	 }

then i test that varriable as follows

Code:
		if(isset($_SESSION['success']) && $_SESSION['success'] == 1){
			echo "<p class='success'><strong>The following record was sucessfully submitted:</strong></p><p class='success'>REALTOR: ".$_SESSION['rltr_firstName']." ".$_SESSION['rltr_familyName']."<br />ADDRESS: ".$_SESSION['address']."</p>";
		}elseif(isset($_SESSION['success']) && $_SESSION['success'] != 1){
	 		echo "<p class='success'>Record submission failed.  Please try again.<br />If problem persits, contact the Regent Signs office.</p>";
		}

It still inserts the record correctly but does not set the session varriable. I know that other sessio nvariables are not working when set on this page becase I simply tired to echo them and before and after the post action they are undefined.

PS. WHy did you use three === signs. How is this different from two ==?
 
Yes the "==" and "===" operators are different.

if ($a == $b)

means "if the value of $a is equal to the value of $b, assuming automatic typecasting where necessary."

if ($a === $b)

means "if the value in $a is equal to and of the same type as the value in $b"

"===" is more strict. This is talked about here:


As jpadie says, dig deeper into what is in $_SESSION. I recommend the use of print_r() or var_dump()



Want the best answers? Ask the best questions! TANSTAAFL!
 
add the following to the query string of the page redirect:
Code:
"?".session_name()."=".session_id()
nb replace the ? with an & depending on where you place this in the query string.
 
Thanks for the reply jpadie

I tried adding your code in the following way:

I changed this code:
Code:
	  $insertGoTo = "comp_submissions.php";
	  if (isset($_SERVER['QUERY_STRING'])) {
		$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
		$insertGoTo .= $_SERVER['QUERY_STRING'];
	  }
	  header(sprintf("Location: %s", $insertGoTo));

to this:
Code:
	  $insertGoTo = "comp_submissions.php";
	  if (isset($_SERVER['QUERY_STRING'])) {
		$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
		$insertGoTo .= $_SERVER['QUERY_STRING'];
		$insertGoTo .= "?".session_name()."=".session_id();		
	  }
	  header(sprintf("Location: %s", $insertGoTo));

The session varriables still did not appear.
However, I inserted a quick test to ensure my logic was working
Code:
	 if ($Result1 === TRUE){
          $_SESSION['success'] = 1;
		  echo "yes";
	 }

and I got the following error:
yes
Warning: Cannot modify header information - headers already sent by (output started at D:\Websites\ in D:\Websites\ on line 313

The interesting thing is that the page then displayed the session variables. I have been able to duplicate this error 100% of the time. If then is any output before the opening html tags the above error is displayed but the session varaibles also display. WHich they do not whne there is no error. I don't know if this helps.
 
in your code the session id would only be appended to a query string that already existed (as it is within the isset test).

i would change this
Code:
$insertGoTo = "comp_submissions.php";
      if (isset($_SERVER['QUERY_STRING'])) {
        $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
        $insertGoTo .= $_SERVER['QUERY_STRING'];
        $insertGoTo .= "?".session_name()."=".session_id();        
      }
      header(sprintf("Location: %s", $insertGoTo));

to the following
Code:
header("Location:comp_submissions.php?".SID."&".$_SERVER['QUERY_STRING']);

sfaik this won't work if your php.ini is set to use only cookies for sessions (and this is the default). the directive is session.use_only_cookies.

fyi the error message you are getting is because you can't cause the browser to redirect by sending a redirect header as you have already output the result of your session success test. once the browser starts getting text to display it "closes" the header information. php is avoiding that problem by stopping script execution.
 
thanks

is this what you mean?

Code:
$SID = session_name()."=".session_id();
	  header("Location:comp_submissions.php?".$SID."&".$_SERVER['QUERY_STRING']);
 
nope. i meant what i posted. just SID. it is a constant that php sets when it knows that a session cookie has not been set. if a cookie has been set the constant is empty (and so does not muck up the redirect) and all will be well with your code.
 
I used your exact code and the url became the following after redirect and the session variables still did not work.

url"...erequest/comp_submissions.php?&

I think it migh tbe time for me to ignore this part of my script as it is not central to the pages functinality. However, I thank you for all your input jpadie

 
for anyone who still cares,

this is the work around I used. I only needed three variables to be available to the updated page and then those variables can disapper. I Stopped trying to use and unset the session varraible and just passed them stright through the url using $GET after the page refreshed as this is non sensitive information.

Code:
$insertGoTo .= 'rltr_fname='.$row_getCustInfo['txtFirstName'].'&rltr_lname='.$row_getCustInfo['txtLastName'].'&rltr_address='.$_POST['address'];
 
re your penultimate post:
this means that php is sending the session cookie just fine (as otherwise SID would be populated). the next stage will be to look at what your cookie jar looks like and what's in the session file.

we can continue trying to fix this through turning to debugging techniques now that the code is right. by i notice in your last post you have a work around. this does not seem ideal but i guess you puts lots of server side validation around the receipt of those GET variables before you use them?
 
Sure,

I would love to fix this thing properly, as my work around is dirty, what is the next step?
 
please insert this code at the end of your comp_submissions.php page and post back the result

Code:
echo "<pre>";
echo "Sessions <br/>";
print_r($_SESSION);

echo "Cookies<br/>";
print_r($_COOKIES);

echo "</pre>";

 
here is the result efore i submit the form:

Code:
Sessions Array
(
    [MM_Username] => rxPolaris
    [MM_UserGroup] => y
    [username] => rxPolaris
    [user_id] => 8
    [cust_id] => 1616
    [first_name] => Realty Executives
    [family_name] => Polaris Office
    [comp_priv] => y
    [comp_id] => 105
)
Cookies
Notice:  Undefined variable: _COOKIES in D:\Websites\[URL unfurl="true"]www.regentsigns.com\erequest\comp_submissions.php[/URL] on line 558

and after I submit the form

Code:
Sessions Array
(
    [MM_Username] => rxPolaris
    [MM_UserGroup] => y
    [username] => rxPolaris
    [user_id] => 8
    [cust_id] => 1616
    [first_name] => Realty Executives
    [family_name] => Polaris Office
    [comp_priv] => y
    [comp_id] => 105
    [success] => 1
    [rltr_firstName] => Barry
    [rltr_familyName] => Candelora
    [address] => 118, 2305-35
)
Cookies
Notice:  Undefined variable: _COOKIES in D:\Websites\[URL unfurl="true"]www.regentsigns.com\erequest\comp_submissions.php[/URL] on line 558

i clear the post array at te end o the insert record event, does that matter?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top