close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Session Variables

Thread began 2/15/2012 11:48 pm by salaroche | Last modified 2/16/2012 9:55 am by Jason Byrnes | 2084 views | 7 replies |

salaroche

Session Variables

Hi:

The MM_Username variable is working well across my Search, Results, etc. pages, but I would need to create another Session Variable to pass some User-entered info around. How do I do that? I've been Googling this for hours, but I haven't found the appropriate answer.

The idea would be to pass the teacher name selected by the user in the Search Page to the rest of the pages. I've tried a few things, but I always get the error message "undefined variable". Any suggestions?

Attached please find a Search and an Update pages.

Thank you for your attention

Attached Files
SessionVariables.zip
Sign in to reply to this post

Jason ByrnesWebAssist

add the following code to the results page at line 1 to set a session variable for each form element from the search page:

php:
<?php

@session_start();
if(
$_SERVER["REQUEST_METHOD"] == "POST")     {
    foreach(
$_POST as $k => $v) {
        
// store as session
        
$_SESSION[$k] = $v;    
    }
}
?>




the teacher element is named S_teacherName, you can use the following code on the update page to reference the session that is created:


php:
<?php @session_start(); echo((isset($_SESSION["S_teacherName"]))?$_SESSION["S_teacherName"]:""?>
Sign in to reply to this post

salaroche

Jason:

Thank you for your reply.

I suppose $v stands for the name of the form element (i.e., S_teacherName) What does $K stand for? A Session Variable name I should come up with?

Sign in to reply to this post

Jason ByrnesWebAssist

$k stands for the key, or element, name. $v stands for the value.


so this line:
$_SESSION[$k] = $v;

creates a session that has the name of the form elements, and sets the value of the session to the value of the form element.

so your S_teacherName form element gets stored in a session named S_teacherName with the value that was posted.

Sign in to reply to this post

salaroche

Jason:

I Replaced both $k with S_teacherName and I created a new Session variable called S_teacherName (is that correct?) But when trying to show the content of S_teacherName I get the following error message:

Notice: Undefined index: S_teacherName in C:\xampp\htdocs\DjibOx.com\AUpdate.php on line 266

Any suggestions?

Sign in to reply to this post

Jason ByrnesWebAssist

you dont need to replace anything in the code i sent you.


use this code unchanged on the results page:

php:
<?php 

@session_start(); 
if(
$_SERVER["REQUEST_METHOD"] == "POST")     { 
    foreach(
$_POST as $k => $v) { 
        
// store as session 
        
$_SESSION[$k] = $v;     
    } 

?>





and this code unchanged:

php:
<?php @session_start(); echo((isset($_SESSION["S_teacherName"]))?$_SESSION["S_teacherName"]:""?>



to display the S_teacherName session variable value

Sign in to reply to this post

salaroche

Jason:

I entered the code unchaged in the corresponding pages, but it doesn't display anything on the AUpdate page. What I am not doing right?

Sign in to reply to this post

Jason ByrnesWebAssist

I have created a support ticket so we can look into this issue further.

To view and edit your support ticket, please log into your support history:
supporthistory.php

If anyone else is experiencing this same issue, please append to this thread.

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