close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Question about Session variables

Thread began 5/09/2012 1:31 pm by iainmacdonald331081 | Last modified 5/10/2012 1:26 pm by iainmacdonald331081 | 2826 views | 8 replies |

iainmacdonald331081

Question about Session variables

Just looking for some advice to see if I'm doing something remotely correctly with Sessions.... (not something I use too often)

I basically have a simple enough database structure with two tables:

Lodges - LodgeID, Lodge, etc
Nominations - NominationID, Nomination, LodgeID, etc

A one-to-many relationship, with each Lodge being able to have multiple Nominations.

So I have a Lodge Details page, which shows the details of a selected Lodge, and a little table listing the Nominations its had.

On this page I have a link to add a new Nomination, which should pick up the LodgeID of the current Lodge, so that the new Nomination is tied to the current Lodge.

So on my Lodge details page I have a session created using:

<?php
if (!session_id()) session_start();
if (!isset($_SESSION["Lodge_ID_Number"])) {
$_SESSION["Lodge_ID_Number"] = "".$row_WADAlodges['LodgeID'] ."";
}
?>

On my Add Nomination page I have a hidden field that calls up the $_SESSION["Lodge_ID_Number"]:

<input type="hidden" name="LodgeID" id="LodgeID" value="<?php echo $_SESSION['Lodge_ID_Number']; ?>" />

And on my Nomination Added page I use unset to clear that Session using:

<?php
unset($_SESSION['Lodge_ID_Number']);
?>

Hope that all makes sense.... it does seem to work, but I'm just interested to know if that's the best way of doing this, or if there's a better way?

The thing that's bugging me is what would happen if the user got as far as the Add Nomination page, and then hit the back button, went to a different Lodge, before the Session variable is cleared which might cause problems?

Sign in to reply to this post

Jason ByrnesWebAssist

i think i would use URL variables instead of using session variables.


the lodge detail page is loaded using a URL Variable:

for example:
detail.php?id=33

nomination.php?id=33

pass that URL Variable to the nomination page, and then store the URL variable in the form element instead of the session

Sign in to reply to this post

iainmacdonald331081

Thanks Jason - is that just using <?php $_GET['LodgeID']; ?> ?

(sorry about the duplicate post by the way - didn't realise I'd done that.)

Sign in to reply to this post

Jason ByrnesWebAssist

that would be correct assuming that LodgeID is the name of the URL variable used to load the details page:

detail.php?LodgeID=33

Sign in to reply to this post

iainmacdonald331081

Sorry Jason - I'm missing something somewhere....

I have a page listing lodges, and the link through the details page ends:

../lodgeDetails.php?LodgeID=438

So the LodgeID is the URL variable?

But I'm missing how to pass that variable from the LodgeDetails page to the AddNomination page.

I've tried echoing it out using:

<?php echo $_GET['LodgeID']; ?>

But it draws a blank, so isn't being passed.

Sign in to reply to this post

Jason ByrnesWebAssist

so on the lodgeDetails page, the link to the add nomination page would look like this:

php:
<a href="AddNomination.php?LodgeID=<?php echo($_GET['LodgeID']); ?>">Add Nomination</a>
Sign in to reply to this post

iainmacdonald331081

Thanks Jason. I think I had always used that going from a results page to a details page, which is set up to pull through the ID to display the details based on the recordset.

But in this case there is no recordset on the AddNomination page, so didn't realise you could use it as simply there too.

One last question on this - my form action is:

<form method="post" id="form1" action="<?php echo KT_escapeAttribute(KT_getFullUri()); ?>">

And then the link to a NominationAdded page is in the php code at the top of the AddNomination page:

$ins_nominations->registerTrigger("END", "Trigger_Default_Redirect", 99, "NominationAdded.php");

What would be useful would be to pass the URL variable through again, so that on the NominationAdded page I can have a link back to the same Lodge to add another Nomination without finding the Lodge again.

But I'm not sure what the syntax would be, as it included some PHP within existing PHP, so not just:

$ins_nominations->registerTrigger("END", "Trigger_Default_Redirect", 99, "nominationAdded.php?LodgeID=echo($_GET['LodgeID'])");

I assume this must be possible, but not sure of the exact syntax?

Sign in to reply to this post

Jason ByrnesWebAssist

i think the correct syntax would be:

$ins_nominations->registerTrigger("END", "Trigger_Default_Redirect", 99, "nominationAdded.php?LodgeID=".$_GET['LodgeID']."");

Sign in to reply to this post

iainmacdonald331081

Thanks Jason - that's working great now. Although now I have a quick question on an SQL Join (posted in Data Assist section)

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...