www.webdeveloper.com
Results 1 to 6 of 6

Thread: Losing Session variable on Post

  1. #1
    Join Date
    Jan 2007
    Location
    Columbia, MD
    Posts
    45

    Losing Session variable on Post

    I have been wrestling with this and getting nowhere so I decided to research and ask. The research did not turn up anything so here goes. I have a form that carries a session variable to another form and works fine. I want to have the user keep submitting that form to enter food preferences until they have entered all they choose. When I submit to the same asp page all of a sudden the Session variables disappear. Is there some rule somewhere that posting to the same page erases session variables? Flummoxed!

  2. #2
    Join Date
    Jun 2012
    Location
    Dark Side of the Moon
    Posts
    70
    Session variables should be kept for the entire time the use is connected to the server, or the session times out. Without code, which you should post up if you need more help, I would say that either something is clearing the item, or the session is clearing out. Try to use a global.asa file and put in Session.Timeout = number of minutes you want to keep session. Most default to 20 minutes, but you can set it to whatever you want. If it isn't that, then you will need to look over your code and make sure something isn't resetting them. If you are adding the info to the same variable make sure you are using Session("myitem") = Session("myitem") & mynewstuff . Also you may want to look into cookies, if you have forms with additions over many pages, make the user save the info on their system, then your server doesn't do all the work, and all the info is stored until you need it. Check out this link for help on cookies: http://www.w3schools.com/asp/asp_cookies.asp

  3. #3
    Join Date
    Jan 2008
    Location
    Florida
    Posts
    1,227
    My guess is you are setting the variable on that page whether it is already set or not. Like burnme said, you need to post your code.

    You may need to do something like:

    if sessionvalue = "" then
    set sessionvalue here
    end if

  4. #4
    Join Date
    Jan 2007
    Location
    Columbia, MD
    Posts
    45

    losing session variable

    Here is the code guys, thanks for looking at it.

    <%@ Language="VbScript"%>

    <!--#include file="./your_db_path.asp"-->

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">

    <html>

    <head>
    <TITLE>Kitchen Karate Add Food Preferences</TITLE>
    <link rel="stylesheet" type="text/css" href="./auth.css">
    <script type="text/javascript" src="js/validateAm.js"></script>
    </HEAD>
    <%
    If Request.ServerVariables("REQUEST_METHOD") = "POST" Then

    'Add choice entered below to a record in database HERE

    'for debug
    Response.Write("Session Fcount is:")
    Response.Write(Session("Fcount"))
    Response.Write("Session Fmembers is:")
    Response.Write(Session("Fmembers"))

    if (Request.Form("B2")="Finished adding items") then

    'if this person's food is added, check if they are the last person and send to final page
    If (Session("Fcount")= Session("Fmembers")) then
    Response.redirect "http://www.kitchenkarate.com/Members/d_PrintList.asp"
    else
    Session("Fcount")=Session("Fcount")+1
    Response.redirect "http://www.kitchenkarate.com/Members/d_AddFmember.asp"

    end if
    else
    Response.redirect "http://www.kitchenkarate.com/Members/d_AddFoods.asp"
    end if

    Else


    %>



    <BODY bgColor="#FFFFFF" Background="">

    <span style="width:317px;height:97px;display:inline-block;
    filterrogidXImageTransform.Microsoft.AlphaImageLoader(src='../images/header-logo-kitchen-karate.png');
    "><img style="
    filterrogidXImageTransform.Microsoft.Alpha(opacity=0);
    " src="../images/header-logo-kitchen-karate.png" width="477" height="96" border="0" alt=""></span>
    Kitchen Karate shopping guide

    <style>input{border:solid 1px black}</style>

    <Center><H1><Font Color="#000000">Add Food </Font></H1>
    <% 'set Food = Preference in Foods table %>
    <table border=0 width=420><tr><td>
    <p>This is where you rate food to store your preferences for future use.</td></tr></table>
    </Center>
    <br>
    <Table border="1" cellpadding="0" cellspacing="0" Align="Center" borderColor="#000000" Background="" >

    <Form Name="Aform" Method="Post" Action="d_AddFoods.asp">


    <input type="hidden" name="Password" value='<%=Session("psw")%>'>
    <TR>
    <TD><Font Face="Arial" Color="#000000">Family of</Font></TD>
    <TD><INPUT Type="text" name="Nuser" value='<%=Session("Uname")%>' ></TD>
    </TR>
    <TR>
    <TD><Font Face="Arial" Color="#000000">FamilyMember</Font></TD>
    <TD><INPUT Type="text" Id="FamilyMembers" name="FamilyMember" value='<%=Session("Fcount")%>' >of <%=Session("Fmembers")%></TD>
    </TR>
    <TR>
    <TD><Font Face="Arial" Color="#000000">Food Item</Font></TD>
    <TD>Preference </TD>
    </TR>
    <TR>
    <TD><select id="food_sel" onclick="document.getElementById('field14').value=
    document.getElementById('food_sel').value;qty14.value='1'" name="txtfood_sel" value="0">
    <option value="Asparagus">Asparagus</option>
    <option value="Broccholi">Broccholi</option>
    <option value="Carrots"> Carrots</option>

    <option value="Chicken">Chicken</option>
    <option value="Pork">Pork</option>
    <option value="Beef">Beef</option>
    </select></TD>
    <TD>
    <input type="radio" name="Preference" value="1">Avoid<input type="radio" name="Asparagus" value="2">Like<input type="radio" name="Asparagus" value="3">Love

    </TD>
    </TR>

    <TR>
    <TD Align="Center" Colspan="2"><INPUT Type="submit" Value="Add Item" name="B1"></TD>
    </TR>


    </TABLE>
    <center><br>
    <INPUT Type="submit" Value="Finished adding items" name="B2">
    </FORM>

    <%
    'for debug
    Response.Write("<br>")
    Response.Write("Session Fcount is:")
    Response.Write(Session("Fcount"))
    Response.Write("Session Fmembers is:")
    Response.Write(Session("Fmembers"))
    End If%>
    </BODY>
    </HTML>

  5. #5
    Join Date
    Jan 2007
    Location
    Columbia, MD
    Posts
    45

    resolved I found it!

    I was searching for a clue in a php forum on session variables and I saw this:
    "Note that this only affects relative URLs, so if your site includes the http:// part in its URLs it will not work for you."
    I looked and sure enough I had put full URL's in my Response.redirect statements and that is what erased the session and the variables. I changed them to relative and the variables stayed put!

  6. #6
    Join Date
    Jun 2012
    Location
    Dark Side of the Moon
    Posts
    70
    Yep that will do it, when you call out to full path you are asking for it to load it up as if it is new, so you were killing your session by loading a new one.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles