PDA

View Full Version : Session Variable probs??


jmx
12-12-2008, 08:27 AM
Hi all,

PHP 5.2

Pulling teeth over this one as just can't get it work although should be very simple.

I am trying to pass a form input value from one page to the next using a session variable- I have the following code on the first page which contains the from:

<?php if (isset($_POST['KT_Insert1'])) {
$add = $_POST['Address'];
$_SESSION['Address'] = $add;}; ?>

And am simply trying to echo the variable on the second with:

<?php echo $_SESSION['Address']; ?>

The first page contains the for with the "Address" field and the complete code is here:

<?php if (!isset($_SESSION)) session_start(); ?>
<?php require_once('Connections/Stuff2do.php'); ?>
<?php
//MX Widgets3 include
require_once('includes/wdg/WDG.php');

// Load the common classes
require_once('includes/common/KT_common.php');

// Load the tNG classes
require_once('includes/tng/tNG.inc.php');

// Make a transaction dispatcher instance
$tNGs = new tNG_dispatcher("");

// Make unified connection variable
$conn_Stuff2do = new KT_connection($Stuff2do, $database_Stuff2do);

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

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($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;
}
}

mysql_select_db($database_Stuff2do, $Stuff2do);
$query_Cities = "SELECT City FROM cities ORDER BY City ASC";
$Cities = mysql_query($query_Cities, $Stuff2do) or die(mysql_error());
$row_Cities = mysql_fetch_assoc($Cities);
$totalRows_Cities = mysql_num_rows($Cities);

mysql_select_db($database_Stuff2do, $Stuff2do);
$query_Recordset1 = "SELECT CatID, EventCat FROM event_categories ORDER BY EventCat ASC";
$Recordset1 = mysql_query($query_Recordset1, $Stuff2do) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

mysql_select_db($database_Stuff2do, $Stuff2do);
$query_Recordset2 = "SELECT * FROM event_subcats ORDER BY subcat_name ASC";
$Recordset2 = mysql_query($query_Recordset2, $Stuff2do) or die(mysql_error());
$row_Recordset2 = mysql_fetch_assoc($Recordset2);
$totalRows_Recordset2 = mysql_num_rows($Recordset2);

// Make an insert transaction instance
$ins_clubs = new tNG_insert($conn_Stuff2do);
$tNGs->addTransaction($ins_clubs);
// Register triggers
$ins_clubs->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "POST", "KT_Insert1");
$ins_clubs->registerTrigger("END", "Trigger_Default_Redirect", 99, "Reg_Club_Pics.php");
// Add columns

$ins_clubs->setTable("clubs");
$ins_clubs->addColumn("ListingCat", "STRING_TYPE", "POST", "select");
$ins_clubs->addColumn("UserID", "NUMERIC_TYPE", "SESSION", "kt_login_id", "{SESSION.kt_login_id}");
$ins_clubs->addColumn("ListSubCat", "STRING_TYPE", "POST", "select1");
$ins_clubs->addColumn("ClubName", "STRING_TYPE", "POST", "Club_Name");
$ins_clubs->addColumn("Discription", "STRING_TYPE", "POST", "Description");
$ins_clubs->addColumn("City", "STRING_TYPE", "POST", "city1");
$ins_clubs->addColumn("Address", "STRING_TYPE", "POST", "Address");
$ins_clubs->addColumn("ClubContact", "STRING_TYPE", "POST", "Email1");
$ins_clubs->setPrimaryKey("ClubID", "NUMERIC_TYPE");

// Execute all the registered transactions
$tNGs->executeTransactions();

// Get the transaction recordset
$rsclubs = $tNGs->getRecordset("clubs");
$row_rsclubs = mysql_fetch_assoc($rsclubs);
$totalRows_rsclubs = mysql_num_rows($rsclubs);

// FELIXONE - 2002 SB by Felice Di Stefano - www.felixone.it

if (isset($_POST['KT_Insert1'])) {
$add = $_POST['Address'];
$_SESSION['Address'] = $add;};

?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:wdg="http://ns.adobe.com/addt">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Stuff2do - Club Registration</title>

<link href="css/screen.css" rel="stylesheet" type="text/css" media="all" />
<link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" />
<link href="SpryAssets/SpryValidationSelect.css" rel="stylesheet" type="text/css" />
<link href="SpryAssets/SpryValidationTextarea.css" rel="stylesheet" type="text/css" />
<link href="SpryAssets/SpryValidationCheckbox.css" rel="stylesheet" type="text/css" />
<link href="SpryAssets/validation.css" rel="stylesheet" type="text/css" media="all" />

<script type="text/javascript" src="SpryAssets/SpryValidationTextField.js"></script>
<script type="text/javascript" src="SpryAssets/SpryValidationSelect.js"></script>
<script type="text/javascript" src="SpryAssets/SpryValidationTextarea.js"></script>
<script type="text/javascript" src="SpryAssets/SpryValidationCheckbox.js"></script>
<script src="includes/skins/style.js" type="text/javascript"></script>
<script src="includes/common/js/base.js" type="text/javascript"></script>
<script src="includes/common/js/utility.js" type="text/javascript"></script>
<script type="text/javascript" src="includes/common/js/sigslot_core.js"></script>
<script type="text/javascript" src="includes/wdg/classes/MXWidgets.js"></script>
<script type="text/javascript" src="includes/wdg/classes/MXWidgets.js.php"></script>
<script type="text/javascript" src="includes/wdg/classes/JSRecordset.js"></script>
<script type="text/javascript" src="includes/wdg/classes/DependentDropdown.js"></script>
<?php
//begin JSRecordset
$jsObject_Recordset2 = new WDG_JsRecordset("Recordset2");
echo $jsObject_Recordset2->getOutput();
//end JSRecordset
?>
<link href="includes/skins/mxkollection3.css" rel="stylesheet" type="text/css" media="all" />

</head>

<body class="oneColFixCtr">

<div id="container">
<div id="mainContent">
<noscript><h1>This page requires JavaScript. Please enable JavaScript in your browser and reload this page.</h1></noscript>
<div id="CentralColumn">
<form id="formReg" name="formReg" method="post">
<div id="formregion">

<div id="Club_Name">
<div class="formLabel">Club Name:</div>
<input name="Club_Name" type="text" class="input" id="Club_Name" value="" />
<span class="textfieldRequiredMsg">Please enter your Clubs Name.</span>
<img src="images/ok.gif" title="Valid" alt="Valid" class="validMsg" border="0"/></div>

<div id="City">
<div class="formLabel">City:</div>
<select name="city1" id="city1">
<option value="" selected><?php echo $_SESSION['kt_City']; ?></option>
<?php
do {
?>
<option value="<?php echo $row_Cities['City']?>"><?php echo $row_Cities['City']?></option>
<?php
} while ($row_Cities = mysql_fetch_assoc($Cities));
$rows = mysql_num_rows($Cities);
if($rows > 0) {
mysql_data_seek($rsCities, 0);
$row_Cities = mysql_fetch_assoc($Cities);
}
?>
</select>
<img src="images/ok.gif" title="Valid" alt="Valid" class="validMsg" border="0"/>
<span class="selectRequiredMsg">Please select a city.</span> </div>
<div id="Address">
<div class="formLabel">Club Address:</div>
<input name="Address" type="text" class="input" id="Address" value="" />
<span class="textfieldRequiredMsg">Please enter your Clubs Address</span>
<img src="images/ok.gif" title="Valid" alt="Valid" class="validMsg" border="0"/></div>


<div id="Cat">
<div class="formLabel">Select a category for your club listing:</div>
<select name="select" id="select">
<option value="" <?php if (!(strcmp("", $row_Recordset1['EventCat']))) {echo "selected=\"selected\"";} ?>>Please Select...</option>
<?php
do {
?><option value="<?php echo $row_Recordset1['CatID']?>"<?php if (!(strcmp($row_Recordset1['CatID'], $row_Recordset1['EventCat']))) {echo "selected=\"selected\"";} ?>><?php echo $row_Recordset1['EventCat']?></option>
<?php
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
$rows = mysql_num_rows($Recordset1);
if($rows > 0) {
mysql_data_seek($Recordset1, 0);
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
}
?>
</select>
<select name="select1" id="select1" wdg:subtype="DependentDropdown" wdg:type="widget" wdg:recordset="Recordset2" wdg:displayfield="subcat_name" wdg:valuefield="SubCatID" wdg:fkey="CatID" wdg:triggerobject="select" wdg:selected="<?php echo $row_Recordset2['subcat_name']; ?>">
</select>

</div>
<div id="Description">
<div class="formLabel">Enter your Club Description:</div>
<textarea name="Description" id="Description" cols="45" rows="5"></textarea>
<img src="images/ok.gif" title="Valid" alt="Valid" class="validMsg" border="0"/>
<span class="textareaRequiredMsg">Please enter a description.</span>
<span class="textareaMinCharsMsg">Please enter at least 100 characters.</span>
<span id="Countvalidta1"> </span> / 2000 </div>
<div id="ContactNum">
<div class="formLabel">Club Contact Phone Number:</div>
<input name="ContactNum" type="text" class="input" id="ContactNum" value="<?php echo $_SESSION['kt_MobileNum']; ?>" />
<img src="images/ok.gif" title="Valid" alt="Valid" class="validMsg" border="0"/>
<span class="textfieldRequiredMsg">Please enter a contact number</span>
<span class="textfieldInvalidFormatMsg">Number format required ###-#######</span> </div>
<div id="Email">
<div class="formLabelEmail">Club Contact Email Address: <em>(This will not be displayed to the public)</em></div>
<input name="Email1" type="text" class="input" id="Email1" value="<?php echo $_SESSION['kt_login_user']; ?>" />
<span class="textfieldRequiredMsg">Please enter a Valid Email Address.</span> <span class="textfieldInvalidFormatMsg">Invalid format</span></div>
<img src="images/ok.gif" title="Valid" alt="Valid" class="validMsg" border="0"/>
</div>

<input name="KT_Insert1" id="KT_Insert1" type="submit" class="submit" value="Next" action="Reg_Club_Pics.php"/>

<?php
echo $tNGs->getErrorMsg();
?>

<input type="hidden" name="ClubID" id="ClubID" />
</form>


</div>



<!-- end #mainContent --></div>
<!-- end #container --></div>
<script type="text/javascript">

var Description = new Spry.Widget.ValidationTextarea("Description", {useCharacterMasking:true, minChars:100, maxChars:2000, counterType:"chars_count", counterId:"Countvalidta1", validateOn:["change"]});
var Club_Name = new Spry.Widget.ValidationTextField("Club_Name", "none", {useCharacterMasking:true, validateOn:["change"]});
var City = new Spry.Widget.ValidationSelect("City", {validateOn:["change"]});
var Address = new Spry.Widget.ValidationTextField("Address", "none", {useCharacterMasking:true, validateOn:["change"]});
var Email = new Spry.Widget.ValidationTextField("Email", "email", {useCharacterMasking:true, validateOn:["blur"]});
var ContactNum = new Spry.Widget.ValidationTextField("ContactNum", "none", {useCharacterMasking:true, format:"\d\d\d-\d\d\d-\d\d\d\d", hint:"###-#######", validateOn:["change"]});
</script>
</body>
</html>
<?php
mysql_free_result($Cities);

mysql_free_result($Recordset1);

mysql_free_result($Recordset2);

?>

I have tried everything with this and have been to many forums and been through untold tutorials however cannot seem to be able to get the form value to pass to the next page (unless I give it an entered value). I don;t get any error messages, but I don;t get the value????? HELPPPP!! Thanks.

ranjan
12-14-2008, 08:18 AM
Read up on session_start

http://us.php.net/function.session-start


<?php
session_start();
echo $_SESSION['Address'];
?>