Skip to main content
Known Participant
June 30, 2007
Question

Storing Recordset in Session Variable

  • June 30, 2007
  • 15 replies
  • 1696 views
How do you store information from a recordset in a session variable?
This topic has been closed for replies.

15 replies

Known Participant
June 30, 2007
But I'm dealing with putting the information from a recordset into a session variable. I don't know what form variables are. Also, why do I need TWO session variables? Why can't I just use one for the recordset field I'm storing? And how do I know if I'm using POST?
Inspiring
June 30, 2007
Nancy - Adobe Comm. Expert wrote:
> PHP sessions are more complicated.

No, they're not.

> You also have to start and
> register sessions like this:
>
> <?php session_start(); // This connects to the existing session
> session_register ("name"); // Create a session variable called name
> session_register ("job"); // Create a session variable called job
> $HTTP_SESSION_VARS ["name"] = $name; // Set name = form variable $name
> $HTTP_SESSION_VARS ["job"] = $job; // Set job = form variable $job
> ?>

No, no, no!!! That is deprecated code that will break on most modern
servers. This is the correct way to write the above example.

<?php
session_start();
$_SESSION['name'] = $name;
$_SESSION['job'] = $job;
?>

If you're using form variables sent by the POST method, then it should
be this:

<?php
session_start();
$_SESSION['name'] = $_POST['name'];
$_SESSION['job'] = $_POST['job'];
?>

For more information about PHP sessions:
http://www.php.net/manual/en/ref.session.php

--
David Powers, Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/
Inspiring
June 30, 2007
PHP sessions are more complicated. You'll have to make sure the host hasn't
disabled them on the server for starters. You also have to start and
register sessions like this:

<?php session_start(); // This connects to the existing session
session_register ("name"); // Create a session variable called name
session_register ("job"); // Create a session variable called job
$HTTP_SESSION_VARS ["name"] = $name; // Set name = form variable $name
$HTTP_SESSION_VARS ["job"] = $job; // Set job = form variable $job
?>



--
Nancy Gill
Adobe Community Expert
Author: Dreamweaver 8 e-book for the DMX Zone
Co-Author: Dreamweaver MX: Instant Troubleshooter (August, 2003)
Technical Editor: Dreamweaver CS3: The Missing Manual,
DMX 2004: The Complete Reference, DMX 2004: A Beginner's Guide
Mastering Macromedia Contribute
Technical Reviewer: Dynamic Dreamweaver MX/DMX: Advanced PHP Web Development


Known Participant
June 30, 2007
I'm using PHP.
Inspiring
June 30, 2007
Create your recordset and then use code like this to set the session.

Session("mysession") =(rsexample.Fields.Item("ColName").Value)


After you do that, you can create a binding in the Data Bindings window by
using the + and choosing Session Variable and naming it mysession (as in the
example). That will create the binding that you can use whereever you wish
on your page to get the value to show up.

Note .. the above is ASP .. you didn't specify your server model.


--
Nancy Gill
Adobe Community Expert
Author: Dreamweaver 8 e-book for the DMX Zone
Co-Author: Dreamweaver MX: Instant Troubleshooter (August, 2003)
Technical Editor: Dreamweaver CS3: The Missing Manual,
DMX 2004: The Complete Reference, DMX 2004: A Beginner's Guide
Mastering Macromedia Contribute
Technical Reviewer: Dynamic Dreamweaver MX/DMX: Advanced PHP Web Development