close ad
WARNING: Do Not Install the DREAMWEAVER CC 2017 or 2018 Update »
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Passing Session Variables - Help?

Thread began 4/27/2009 7:23 am by phil.evans372967 | Last modified 4/28/2009 8:10 am by phil.evans372967 | 3811 views | 7 replies |

phil.evans372967

Passing Session Variables - Help?

Hi all,

I'm having trouble trying to pass a variable from one page/form to another and hope you can help.

I have two tables - prop_details and prop_images - I created a relationship using prop_id in both tables.

My first insert form posts data to prop_details and then redirects to my second page/form where I want to display two session variables (prop_id and prop_ref from prop_details) and then pass those to prop_images to create the relationship.

I have created a recordset in my 2nd page/form but cannot display the two session variable to post to prop_images

SELECT prop_id, prop_ref
FROM prop_details
WHERE prop_id = colname

what am I doing wrong?

With thanks

Phil

Sign in to reply to this post

phil.evans372967

Update

Thought I'd post my code as it may be helpful. Pulling may hair out trying to get this to work

<?php require_once("Connections/prop.php"); ?>
<?php require_once("WA_DataAssist/WA_AppBuilder_PHP.php"); ?>
<?php require_once('Connections/prop.php'); ?>
<?php
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;
}
}

$colname_GetIDsForIms = "-1";
if (isset($_SESSION['prop_id'])) {
$colname_GetIDsForIms = (get_magic_quotes_gpc()) ? $_SESSION['prop_id'] : addslashes($_SESSION['prop_id']);
}
mysql_select_db($database_prop, $prop);
$query_GetIDsForIms = sprintf("SELECT prop_id, prop_ref FROM prop_details WHERE prop_id = %s ORDER BY prop_id ASC", GetSQLValueString($colname_GetIDsForIms, "int"));
$GetIDsForIms = mysql_query($query_GetIDsForIms, $prop) or die(mysql_error());
$row_GetIDsForIms = mysql_fetch_assoc($GetIDsForIms);
$totalRows_GetIDsForIms = mysql_num_rows($GetIDsForIms);?>
<?php
// WA Application Builder Insert
if (isset($_POST["Insert_x"])) // Trigger
{
$WA_connection = $prop;
$WA_table = "prop_images";
$WA_sessionName = "WADA_Insert_prop_images";
$WA_redirectURL = "prop_images_Insert.php";
$WA_keepQueryString = true;
$WA_indexField = "img_id";
$WA_fieldNamesStr = "img_id|img_thumb|img_main|prop_id|prop_ref";
$WA_fieldValuesStr = "".((isset($_POST["img_id"]))?$_POST["img_id"]:"") ."" . "|" . "".((isset($_POST["img_thumb"]))?$_POST["img_thumb"]:"") ."" . "|" . "".((isset($_POST["img_main"]))?$_POST["img_main"]:"") ."" . "|" . "".$row_GetIDsForIms['prop_id'] ."" . "|" . "".$row_GetIDsForIms['prop_ref'] ."";
$WA_columnTypesStr = "none,none,NULL|',none,''|',none,''|none,none,NULL|',none,''";
$WA_fieldNames = explode("|", $WA_fieldNamesStr);
$WA_fieldValues = explode("|", $WA_fieldValuesStr);
$WA_columns = explode("|", $WA_columnTypesStr);
$WA_connectionDB = $database_prop;
mysql_select_db($WA_connectionDB, $WA_connection);
if (!session_id()) session_start();
$insertParamsObj = WA_AB_generateInsertParams($WA_fieldNames, $WA_columns, $WA_fieldValues, -1);
$WA_Sql = "INSERT INTO `" . $WA_table . "` (" . $insertParamsObj->WA_tableValues . ") VALUES (" . $insertParamsObj->WA_dbValues . ")";
$MM_editCmd = mysql_query($WA_Sql, $WA_connection) or die(mysql_error());
$_SESSION[$WA_sessionName] = mysql_insert_id();
if ($WA_redirectURL != "") {
if ($WA_keepQueryString && $WA_redirectURL != "" && isset($_SERVER["QUERY_STRING"]) && $_SERVER["QUERY_STRING"] !== "" && sizeof($_POST) > 0) {
$WA_redirectURL .= ((strpos($WA_redirectURL, '?') === false)?"?":"&").$_SERVER["QUERY_STRING"];
}
header("Location: ".$WA_redirectURL);
}
}
?>
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Insert prop_images</title>
<link href="WA_DataAssist/styles/Refined_Pacifica.css" rel="stylesheet" type="text/css" />
<link href="WA_DataAssist/styles/Arial.css" rel="stylesheet" type="text/css" />
</head>

<body>

<div class="WADAInsertContainer">
<form action="prop_images_Insert.php" method="post" name="WADAInsertForm" id="WADAInsertForm">
<div class="WADAHeader">Insert Record</div>
<div class="WADAHorizLine"><img src="WA_DataAssist/images/_tx_.gif" alt="" height="1" width="1" border="0" /></div>
<table class="WADADataTable" cellpadding="0" cellspacing="0" border="0">
<tr>
<th class="WADADataTableHeader">img_id:</th>
<td class="WADADataTableCell"><input type="hidden" name="img_id" id="img_id" value="" /></td>
</tr>
<tr>
<th class="WADADataTableHeader">img_thumb:</th>
<td class="WADADataTableCell"><input type="text" name="img_thumb" id="img_thumb" value="" size="32" /></td>
</tr>
<tr>
<th class="WADADataTableHeader">img_main:</th>
<td class="WADADataTableCell"><input type="text" name="img_main" id="img_main" value="" size="32" /></td>
</tr>
<tr>
<th class="WADADataTableHeader">prop_id:</th>
<td class="WADADataTableCell"><?php echo $row_GetIDsForIms['prop_id']; ?></td>
</tr>
<tr>
<th class="WADADataTableHeader">prop_ref:</th>
<td class="WADADataTableCell"><?php echo $row_GetIDsForIms['prop_ref']; ?></td>
</tr>
</table>
<div class="WADAHorizLine"><img src="WA_DataAssist/images/_tx_.gif" alt="" height="1" width="1" border="0" /></div>
<div class="WADAButtonRow">
<table class="WADADataNavButtons" border="0" cellpadding="0" cellspacing="0">
<tr>
<td class="WADADataNavButtonCell" nowrap="nowrap"><input type="image" name="Insert" id="Insert" value="Insert" alt="Insert" src="WA_DataAssist/images/Pacifica/Refined_insert.gif" /></td>
<td class="WADADataNavButtonCell" nowrap="nowrap"><a href="prop_images_Results.php" title="Cancel"><img border="0" name="Cancel" id="Cancel" alt="Cancel" src="WA_DataAssist/images/Pacifica/Refined_cancel.gif" /></a></td>
</tr>
</table>
<input name="WADAInsertRecordID" type="hidden" id="WADAInsertRecordID" value="" />
</div>
</form>
</div>
</body>
</html>
<?php
mysql_free_result($GetIDsForIms);
?>

Sign in to reply to this post

Ray BorduinWebAssist

Add code to the top of your page:

<?php
if (!session_id()) session_start();
?>

Sign in to reply to this post

phil.evans372967

Still no joy

Hi Ray

Thanks for your help.

I have added that the the top of my second page and still can't get the 2 session variables to display. I've spent 3 days on this now and I'm sure I'm doing something simple wrong, but can't see the wood for the trees.

My code now looks like this

<?php
if (!session_id()) session_start();
?>
<?php require_once("../Connections/prop.php"); ?>
<?php require_once("../WA_DataAssist/WA_AppBuilder_PHP.php"); ?>
<?php require_once('../Connections/prop.php'); ?>
<?php
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;
}
}

$colname_Recordset1 = "-1";
if (isset($_SESSION['prop_id'])) {
$colname_Recordset1 = (get_magic_quotes_gpc()) ? $_SESSION['prop_id'] : addslashes($_SESSION['prop_id']);
}
mysql_select_db($database_prop, $prop);
$query_Recordset1 = sprintf("SELECT prop_id, prop_ref FROM prop_details WHERE prop_id = %s", GetSQLValueString($colname_Recordset1, "int"));
$Recordset1 = mysql_query($query_Recordset1, $prop) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);?>
<?php
// WA Application Builder Insert
if (isset($_POST["Insert_x"])) // Trigger
{
$WA_connection = $prop;
$WA_table = "prop_images";
$WA_sessionName = "WADA_Insert_prop_images";
$WA_redirectURL = "prop_images_Results.php";
$WA_keepQueryString = false;
$WA_indexField = "img_id";
$WA_fieldNamesStr = "img_thumb|img_main|prop_id|prop_ref";
$WA_fieldValuesStr = "".((isset($_POST["img_thumb"]))?$_POST["img_thumb"]:"") ."" . "|" . "".((isset($_POST["img_main"]))?$_POST["img_main"]:"") ."" . "|" . "".$row_Recordset1['prop_id'] ."" . "|" . "".$row_Recordset1['prop_ref'] ."";
$WA_columnTypesStr = "',none,''|',none,''|none,none,NULL|',none,''";
$WA_fieldNames = explode("|", $WA_fieldNamesStr);
$WA_fieldValues = explode("|", $WA_fieldValuesStr);
$WA_columns = explode("|", $WA_columnTypesStr);
$WA_connectionDB = $database_prop;
mysql_select_db($WA_connectionDB, $WA_connection);
if (!session_id()) session_start();
$insertParamsObj = WA_AB_generateInsertParams($WA_fieldNames, $WA_columns, $WA_fieldValues, -1);
$WA_Sql = "INSERT INTO `" . $WA_table . "` (" . $insertParamsObj->WA_tableValues . ") VALUES (" . $insertParamsObj->WA_dbValues . ")";
$MM_editCmd = mysql_query($WA_Sql, $WA_connection) or die(mysql_error());
$_SESSION[$WA_sessionName] = mysql_insert_id();
if ($WA_redirectURL != "") {
if ($WA_keepQueryString && $WA_redirectURL != "" && isset($_SERVER["QUERY_STRING"]) && $_SERVER["QUERY_STRING"] !== "" && sizeof($_POST) > 0) {
$WA_redirectURL .= ((strpos($WA_redirectURL, '?') === false)?"?":"&").$_SERVER["QUERY_STRING"];
}
header("Location: ".$WA_redirectURL);
}
}
?>
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Insert prop_images</title>
<link href="../WA_DataAssist/styles/Refined_Pacifica.css" rel="stylesheet" type="text/css" />
<link href="../WA_DataAssist/styles/Arial.css" rel="stylesheet" type="text/css" />
</head>

<body>

<div class="WADAInsertContainer">
<form action="prop_images_Insert.php" method="post" name="WADAInsertForm" id="WADAInsertForm">
<div class="WADAHeader">Insert Record</div>
<div class="WADAHorizLine"><img src="../WA_DataAssist/images/_tx_.gif" alt="" height="1" width="1" border="0" /></div>
<table class="WADADataTable" cellpadding="0" cellspacing="0" border="0">
<tr>
<th class="WADADataTableHeader">img_id:</th>
<td class="WADADataTableCell"></td>
</tr>
<tr>
<th class="WADADataTableHeader">img_thumb:</th>
<td class="WADADataTableCell"><input type="text" name="img_thumb" id="img_thumb" value="" size="32" /></td>
</tr>
<tr>
<th class="WADADataTableHeader">img_main:</th>
<td class="WADADataTableCell"><input type="text" name="img_main" id="img_main" value="" size="32" /></td>
</tr>
<tr>
<th class="WADADataTableHeader">prop_id:</th>
<td class="WADADataTableCell"><?php echo $row_Recordset1['prop_id']; ?></td>
</tr>
<tr>
<th class="WADADataTableHeader">prop_ref:</th>
<td class="WADADataTableCell"><?php echo $row_Recordset1['prop_ref']; ?></td>
</tr>
</table>
<div class="WADAHorizLine"><img src="../WA_DataAssist/images/_tx_.gif" alt="" height="1" width="1" border="0" /></div>
<div class="WADAButtonRow">
<table class="WADADataNavButtons" border="0" cellpadding="0" cellspacing="0">
<tr>
<td class="WADADataNavButtonCell" nowrap="nowrap"><input type="image" name="Insert" id="Insert" value="Insert" alt="Insert" src="../WA_DataAssist/images/Pacifica/Refined_insert.gif" /></td>
<td class="WADADataNavButtonCell" nowrap="nowrap"><a href="prop_images_Results.php" title="Cancel"><img border="0" name="Cancel" id="Cancel" alt="Cancel" src="../WA_DataAssist/images/Pacifica/Refined_cancel.gif" /></a></td>
</tr>
</table>
<input name="WADAInsertRecordID" type="hidden" id="WADAInsertRecordID" value="" />
</div>
</form>
</div>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>

Sign in to reply to this post

Ray BorduinWebAssist

The problem must be where they are set, since they are referenced correctly here.

Sign in to reply to this post

phil.evans372967

have i set them wrong?

Here's my first page. Does dataassist set them automatically or do I need to manually set them somehow?

Sign in to reply to this post

phil.evans372967

Sorry Ray, thought I'd attached my code. Will try again ...

Attached Files
prop_insert.txt
Sign in to reply to this post

phil.evans372967

Update

Hi Ray

I figured it out and added

$_SESSION['WADA_Insert_prop_details'] into my recordset for my second form, WADA_Insert_prop_details being the session variable from my first form and that seems to work fine.

Thanks for your help.

Regards

Phil

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...