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

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

$Session variable hell

Thread began 8/18/2009 10:53 pm by david.barrack304604 | Last modified 8/19/2009 1:23 pm by anonymous | 3245 views | 6 replies |

david.barrack304604

$Session variable hell

I am wanting to assign a value in a recordset to a session variable and having no luck. It seems easy enough. I have session_start at the top of the page and then later assign $_SESSION['room_number'] = $row_Recordset1['PRV_Room'] but it just does not work. No value is assigned to the session variable. I believe I am using PHP 5. Do I need to use session_register as part of this?

It seems when it rains it pours. I wanted to simply display a recordset value using the following:

EVENTID = <?php echo $row_Recordset1['PRV_Event_ID']; ?>

and although the recordset displays fine on the page, the statement just above just shows nothing after the EVENTID text; ie, EVENTID =

Sign in to reply to this post

anonymous

David,

Are both of these issues spurring from the same query? It looks that way, but I don't want to assume.

One of things I would do is make sure that query is really valid and is supplying a value. Maybe go to the top of the page just below the query and use the echo command for debugging purposes. Have it echo those two values from the query before you try to store them into variables. It will probably crash the page but should show exactly - if at all - what the values of each binding are.

If the values are there, then you may have something else wrong with your code. Perhaps and if statement that is keeping code from running the way you want... it really could be anything. If you want to post your code (or you could email it to me if it contains sensitive coding you don't want to share here), I will take a look at it. My email address is sojoweb(at)rocketmail.com.

Cheers,

Brian

Sign in to reply to this post

david.barrack304604

code with SESSION variable issues

Hi Brian,

Thank you so much for the help. I am attaching the code. I made sure that session_start was at the top of the page. The recordset works with no problems and returns and displays value.

I am just seeing weird things. At one time this seemed to work fine. Listed below are a few lines I was adding to check out values.

1) Here I am just wanting to see one of the values from the recordset. This used to work but does not now. The recordset does work and does display in a dynamic table. EVENTID = <?php echo $row_Recordset1['PRV_Event_ID']; ?>

2) This is a session variable assigned a value just to see if the session variable would at least store something. ?php $_SESSION['PRV_rates'] = 9;?>

3) Here is where I am attempting to story a recordset value in the session variable.
?php $_SESSION['PRV_rates'] = $row_Recordset1['PRV_Event_ID'];?>

4) Here I am expecting to either see the static value I assigned to the session variable or hopefully the recordset value. Instead I get nothing. Nada.
rates = <?php $_SESSION['PRV_rates'];?>

*************************************************

Attached Files
From David BARRACK.doc.zip
Sign in to reply to this post

Jason ByrnesWebAssist

Hi David,


to output a session variables value to the page, you need to use an output function such as print() or echo().


Try changing:

php:
<p>rates = <?php $_SESSION['PRV_rates'];?></p>



to:

php:
<p>rates = <?php echo($_SESSION['PRV_rates']); ?></p>
Sign in to reply to this post

david.barrack304604

Adding echo, same result.

Hi Brian,

I must have missed that on an iteration, but I'm still not seeing a value at all. The first line where I am trying to display the recordset is doing nothing as well and that had an echo. The recordset works like I mentioned and displays data in the dynamic table with no problem. I'm stumped. Is there possibly something with the Dreamweaver config or maybe PHP at GoDaddy is configured such that session variables are not working?


<p>EVENTID = <?php echo $row_Recordset1['PRV_Event_ID']; ?></p>
<?php $_SESSION['PRV_rates'] = 9;?>
<?php $_SESSION['PRV_rates'] = $row_Recordset1['PRV_Event_ID'];?>
<p>rates = <?php echo($_SESSION['PRV_rates']);?></p>

Sign in to reply to this post

anonymous

That is because it comes after your loop... if you were to place that code above the loop (dynamic table), it works fine... but you cannot place it after the dynamic table without doing a completely separate query... the do while loop you have has set that variable several times.

Sign in to reply to this post

anonymous

Hi David,

Ok a couple of things now that I see the code after creating a database table with your fields and testing.

You have a "Do while" loop which is setting the variables through several variations so it's not going to be possible after the loop. Because, remember if you just echo the row variable, it will take just the first one... but since the loop has already set that same variable in many different iterations, it will simply make what your trying to do null.

Now, if you want to just get the first record, you could do that before the loop and store the result into a new variable or you could create a separate query for the single record below the loop.

Your session variable actually works fine but when you try to combine it with the aforementioned PRV_Event_ID, it too then becomes NULL because the PRV_Event_ID is no longer a valid result. If you were to just set the session and then echo the session variable, it shows exactly as it should.

But, if you do a separate query to set the PRV_Event_ID, it will work fine in combination with the Session variable you have. But, keep in mind, you'll only get the first record there as well unless you loop through the results. You could also set the PRV_Event_ID and get the calculation of the session with it inside the loop you already have... you would just need to make and extra table cell and put the code you have after your loop inside that cell instead.

One other housekeeping issue I noticed was on your "rates =", you left out the "echo" before the variable which is what was keeping you from seeing just the display of your session variable.

Hopefully that helps... let me know if I didn't explain something clearly.

Shalom,

Brian

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