• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 194
  • Last Modified:

undefined session variable...shuld be defined as i define it in my code

I get the following error

Element USER.CART.SHIPPINGMETHOD2 is undefined in SESSION.  
 
 
The error occurred in C:\CFusionMX\wwwroot\Andysite\login.cfm: line 720
Called from C:\CFusionMX\wwwroot\Andysite\login.cfm: line 682
Called from C:\CFusionMX\wwwroot\Andysite\login.cfm: line 1
 
718 :                       <cfset estDate = dateAdd("d",getSelectedShipping.shippingdays ,now())>
719 :                         
720 :                           <b class="labelstrong">Shipping Method:</b> <font class="label">#getSelectedShipping.shippingname# #dollarFormat(session.user.cart.shippingMethod2)#</font><br/>
721 :                       <b class="labelstrong">Estimated Arrival Date:</b>  <font class="label">#dateFormat(session.user.cart.shippingMethod3,
722 :                               'mmm dd, yyyy')#</font>

 ******************************************************
THE CODE IS BELOW THAT GENERATES THE ERROR, NOTICE I ALREADY DEFINE session.user.cart.shippingMethod2 in the code BEFORE!! i call it

*******************************************************
<TABLE cellspacing=0 cellpadding=0 width=779 align=right bgcolor=#efefef
border=0>
  <!--DWLayoutTable-->
  <TBODY>
    <TR>
      <TD height="18" colspan=6>
<cfsilent>
<cfparam name="url.step" default="1">      
<cfparam name="form.step" default="#url.step#">
<cfif isDefined("form.continue_submit") or isDefined ("form.hideme")>
      <cfscript>
            if( form.step eq 1 )
            {
                  if( form.type eq "returning" )
                  {
                        status = session.user.login( email=form.email, password=form.password );
                        if( variables.status )
                        {
                              //login successfull, continue with checkout
                              form.step = 2;
                        }else if( not variables.status ){
                              //login unsuccessful
                              errorMessage = "Login unsuccessful, try again";
                              form.step = 1;
                        }
                  }else if( form.type eq "new" )
                  {
                        status = session.user.checkEmail( email=form.email );
                        if( not variables.status ){
                              //no existing account that matches the email/password
                              session.user.email = form.email;
                              session.user.password = form.password;
                              // need to manually clear out all user info in case they already logged in but decided to create a new user
                              session.user.billing.firstname = "";
                              session.user.billing.lastname = "";
                              session.user.billing.givenname = "";
                              session.user.billing.familyname = "";
                              session.user.phone1 = "";      
                              session.user.billing.street1 = "";
                              session.user.billing.street2 = "";
                              session.user.billing.city = "";
                              session.user.billing.state = "";
                              session.user.billing.zipcode = "";
                              session.user.billing.country = "";
                              session.user.shipping.firstname = "";
                              session.user.shipping.lastname = "";
                              session.user.shipping.street1 = "";
                              session.user.shipping.street2 = "";
                              session.user.shipping.city = "";
                              session.user.shipping.state = "";
                              session.user.shipping.zipcode = "";
                              session.user.shipping.country = "";
                              session.user.cart.shippingMethod = "3";
                              session.user.cart.shippingMethod2 = "077";
                              session.user.creditcard.type = "";
                              session.user.creditcard.number = "";
                              session.user.creditcard.expiration = "";
                              //
                              form.step = 2;
                        }else if( variables.status ){
                              //account already exists,
                              errorMessage = "account already exists, login in as a returning user instead.";
                              form.step = 1;
                        }
                  }

            }else if( form.step eq 2 ) {
                  session.user.familyname = form.lastname;
                  session.user.givenname = form.firstname;
                  session.user.phone1 = form.phone;            
                  //session.user.email = form.email;
                  
                  session.user.billing.firstname = form.firstname;
                  session.user.billing.lastname = form.lastname;
                  session.user.billing.street1 = form.street1;
                  session.user.billing.street2 = form.street2;
                  session.user.billing.city = form.city;
                  session.user.billing.state = form.state;
                  session.user.billing.zipcode = form.zipcode;
                  session.user.billing.country = form.country;
                  
                  if( isDefined("form.shippingSameAsBilling") )
                  {
                        session.user.shipping.firstname = form.firstname;
                        session.user.shipping.lastname = form.lastname;
                        session.user.shipping.street1 = form.street1;
                        session.user.shipping.street2 = form.street2;
                        session.user.shipping.city = form.city;
                        session.user.shipping.state = form.state;
                        session.user.shipping.zipcode = form.zipcode;
                        session.user.shipping.country = form.country;
                  }
                  
                  form.step = 3; //set was successful move to next step

            }else if( form.step eq 3 ) {
                  session.user.shipping.firstname = form.firstname;
                  session.user.shipping.lastname = form.lastname;
                  session.user.shipping.street1 = form.street1;
                  session.user.shipping.street2 = form.street2;
                  session.user.shipping.city = form.city;
                  session.user.shipping.state = form.state;
                  session.user.shipping.zipcode = form.zipcode;
                  session.user.shipping.country = form.country;
                  
                  form.step = 4; //set was successful move to next step
                  
            }else if( form.step eq 4  and form.hideme eq 2 ) {
                  session.user.cart.shippingMethod = form.shippingMethod;

                  form.step = 4; //set was successful move to next step}
            }else if( form.step eq 4  and form.hideme eq 0) {
                  session.user.cart.shippingMethod = form.shippingMethod;
                  session.user.cart.shippingMethod2 = form.hideme2;
                  session.user.cart.shippingMethod3 = form.hideme3;
                  
                  form.step = 5; //set was successful move to next step}
            }else if( form.step eq 5 ) {
                  session.user.creditcard.type = form.ccType;
                  session.user.creditcard.number = form.ccNumber;
                  session.user.creditcard.expiration = "#form.ccExpMonth#/#form.ccExpYear#";
                  session.user.creditcard.expiration1 = "#form.ccExpMonth##form.ccExpYear#";
                  session.user.cart.taxme = "0.00";
                  status = session.user.placeorder2(session.user.shipping.city,session.user.shipping.street1,session.user.shipping.state,session.user.shipping.country,session.user.shipping.firstname,session.user.shipping.lastname,session.user.phone1,session.user.shipping.zipcode,session.user.shipping.lastname,session.user.creditcard.number,session.user.creditcard.expiration1, session.user.cart.getCartTotal(), session.user.cart.taxme, session.user.cart.shippingMethod2, session.user.email, session.user.billing.city,session.user.billing.street1,session.user.billing.state,session.user.billing.country,session.user.billing.firstname,session.user.billing.firstname,session.user.billing.firstname,session.user.billing.zipcode);
                  
                  form.step = 6; //set was successful move to next step
                  
            }else if( form.step eq 6 ) {
                  status = session.user.placeorder(session.user.shipping.city,session.user.shipping.street1,session.user.shipping.state,session.user.shipping.country,session.user.shipping.firstname,session.user.shipping.lastname,session.user.phone1,session.user.shipping.zipcode,session.user.shipping.lastname,session.user.creditcard.number,session.user.creditcard.expiration1, session.user.cart.getCartTotal(), session.user.cart.taxme, session.user.cart.shippingMethod2, session.user.email, session.user.billing.city,session.user.billing.street1,session.user.billing.state,session.user.billing.country,session.user.billing.firstname,session.user.billing.firstname,session.user.billing.firstname,session.user.billing.zipcode,session.user.cart.shippingMethod);
                  
                  //set was successful set message text.
                  if( status )
                  {
                        form.step = 7;
                  }else {
                        statusmessage = "There was an error placing your order, please try again.<br>If the problem continues please call our 800 customer service number.<br>Thank You.";
                        form.step = 6;
                  }

                  
            }
            
      </cfscript>
      </cfif>




<cfquery name="getShippingMethods" datasource="#application.datasource#" cachedwithin="#createTimeSpan(1,0,0,0)#">
      select shippingoid, upsvalue, shippingname, shippingdescription, shippingprice, shippingdays
      from shippingmethod
      order by shippingprice
</cfquery>

<cfquery name="getStateList" datasource="#application.datasource#" cachedwithin="#createTimeSpan(1,0,0,0)#">
      select distinct state
      from zip
      order by statename
</cfquery>




</cfsilent>

<cfoutput>&nbsp;
            <b class="labelstrong">1) <cfif form.step gt 1 and form.step lt 7><a href="#cgi.script_name#?step=1"></cfif>Login</a></b>      &nbsp;
            <b class="labelstrong">2) <cfif form.step gt 2 and form.step lt 7><a href="#cgi.script_name#?step=2"></cfif>Customer Details / Billing Address</a></b>
            <table border="0" cellpadding="10" cellspacing="0" width="100%">
              <tr>
                    <td><font class="label">
                          #session.user.givenname# #session.user.familyname# <br />
                          #session.user.email# <br />
                          <cfif len(session.user.phone1)>#session.user.phone1# <br /></cfif>
                          <cfif len(session.user.billing.street1)>#session.user.billing.street1#<br /></cfif>
                          <cfif len(session.user.billing.street2)>#session.user.billing.street2#<br /></cfif>
                          #session.user.billing.city# / #session.user.billing.state# / #session.user.billing.zipcode#<br />
                          </font>
                    </td>
              </tr>
            </table>
            <b class="labelstrong">&nbsp; 3) <cfif form.step gt 3 and form.step lt 7><a href="#cgi.script_name#?step=3"></cfif>Shipping Address</a></b>
            <table border="0" cellpadding="10" cellspacing="0" width="100%">
              <tr>
                    <td colspan="2"><font class="label">
                          #session.user.shipping.firstname# #session.user.shipping.lastname# <br />
                          <cfif len(session.user.shipping.street1)>#session.user.shipping.street1#<br /></cfif>
                          <cfif len(session.user.shipping.street2)>#session.user.shipping.street2#<br /></cfif>
                          #session.user.shipping.city# / #session.user.shipping.state# / #session.user.shipping.zipcode#<br /></font>
                    </td>
              </tr>
            </table>
            <b class="labelstrong">&nbsp; 4) <cfif form.step gt 4 and form.step lt 7><a href="#cgi.script_name#?step=4"></cfif>Shipping Options</a></b>
            <table border="0" cellpadding="10" cellspacing="0" width="100%">
              <tr>
                <td>
                          <cfquery name="getSelectedShipping" dbtype="query">
                                select shippingoid, shippingname, shippingdescription, shippingprice, shippingdays
                                    from getShippingMethods
                                    where upsvalue = #session.user.cart.shippingMethod#
                          </cfquery>
                      <cfset estDate = dateAdd("d",getSelectedShipping.shippingdays ,now())>
                        
                          <b class="labelstrong">Shipping Method:</b> <font class="label">#getSelectedShipping.shippingname# #dollarFormat(session.user.cart.shippingMethod2)#</font><br/>
                      <b class="labelstrong">Estimated Arrival Date:</b>  <font class="label">#dateFormat(session.user.cart.shippingMethod3,
                              'mmm dd, yyyy')#</font>
                    </td>
              </tr>
            </table>
0
finnstone
Asked:
finnstone
1 Solution
 
pinaldaveCommented:
This is strange.
I am not sure what is the error but we can try few things.
1) try to remove cfsilent and run the code
2) try to put session.ur.car.shippingmethod2 = 077 instead of "077"
3) try this number format which is like this ... #numberformat(session.user.cart.shippingMethod2, "$____.__")#

regards,
---Pinal
0
 
MauseCommented:

use CFDUMP to see if CART.SHIPPINGMETHOD2 realy is defined in session.user

Mause
0
 
anandkpCommented:
are u sure its getting initialised - as its inside a "if--else" condition block ... just a thought !
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
mrichmonCommented:
or use a cfparam to set a default value and then if you see the default value you know it wasn't set
0
 
Jerry_PangCommented:
what is the value of form.step?

step 1 & new
set

step 1 & returning
not set

step 2
not set

step 3
not set

step 4 & hideme=2
set

step 4 & hideme=0
notset

....
not set
the only way shippingmethod is set is through
step 1 new or step 4 hideme=2

are you sure it started with step one and new (not returning?)

to be sure, just initialize all the session.user before you start.
use cfparam as they suggested or initialize everything on the start of the code.

0
 
finnstoneAuthor Commented:
the steps are used this code which is immediately after the code already posted (notice a different page is loaded depeding on step #)


<tr>
      <td bgcolor="#iif(form.step gt 3, de("ddddcc"), de("ffee99"))#" height="18">
            <b class="labelstrong">&nbsp; 3) <cfif form.step gt 3 and form.step lt 7><a href="#cgi.script_name#?step=3"></cfif>Shipping Address</a></b>
      </td>
</tr>
<cfif form.step eq 3>
      <cfinclude template="_checkout_step3.cfm">

<cfelseif form.step gt 3 and form.step lt 6>
<tr bgcolor="fffff0">
      <td>
            <table border="0" cellpadding="10" cellspacing="0" width="100%">
                  <tr>
                        <td colspan="2"><font class="label">
                              #session.user.shipping.firstname# #session.user.shipping.lastname# <br />
                              <cfif len(session.user.shipping.street1)>#session.user.shipping.street1#<br /></cfif>
                              <cfif len(session.user.shipping.street2)>#session.user.shipping.street2#<br /></cfif>
                              #session.user.shipping.city# / #session.user.shipping.state# / #session.user.shipping.zipcode#<br /></font>
                        </td>
                  </tr>
            </table>
      </td>
</tr>
</cfif>




<tr>
      <td bgcolor="#iif(form.step gt 4, de("ddddcc"), de("ffee99"))#" height="18">
            <b class="labelstrong">&nbsp; 4) <cfif form.step gt 4 and form.step lt 7><a href="#cgi.script_name#?step=4"></cfif>Shipping Options</a></b>
      </td>
</tr>
<cfif form.step eq 4>
      <cfinclude template="_checkout_step4.cfm">
<cfelseif form.step gt 3 and form.step lt 6>
<tr bgcolor="fffff0">
      <td>
            <table border="0" cellpadding="10" cellspacing="0" width="100%">
                  <tr>
                    <td>
                              <cfquery name="getSelectedShipping" dbtype="query">
                                    select shippingoid, shippingname, shippingdescription, shippingprice, shippingdays
                                    from getShippingMethods
                                    where upsvalue = #session.user.cart.shippingMethod#
                              </cfquery>
                          <cfset estDate = dateAdd("d",getSelectedShipping.shippingdays ,now())>
                        
                              <b class="labelstrong">Shipping Method:</b> <font class="label">#getSelectedShipping.shippingname# #dollarFormat(session.user.cart.shippingMethod2)#</font><br/>
                          <b class="labelstrong">Estimated Arrival Date:</b>  <font class="label">#dateFormat(session.user.cart.shippingMethod3,
                              'mmm dd, yyyy')#</font>
                        </td>
                  </tr>
            </table>
      </td>
</tr>
</cfif>




<tr>
      <td bgcolor="#iif(form.step gt 5, de("ddddcc"), de("ffee99"))#" height="18">
            <b class="labelstrong">&nbsp; 5) <cfif form.step gt 5 and form.step lt 7><a href="#cgi.script_name#?step=5"></cfif>Payment Method</a></b>
      </td>
</tr>
<cfif form.step eq 5>
      <cfinclude template="_checkout_step5.cfm">
<cfelseif form.step gt 4 and form.step lt 6>
<tr bgcolor="fffff0">
      <td>
            <table border="0" cellpadding="10" cellspacing="0" width="100%">
                  <tr>
                        <td colspan="2">
                              <b class="labelstrong">Credit Card Type:</b> #session.user.creditcard.type# <br />
                              <b class="labelstrong">Number:</b> #session.user.creditcard.number# <br />
                              <b class="labelstrong">Expiration Date:</b> #session.user.creditcard.expiration# <br />
                        </td>
                  </tr>
            </table>
      </td>
</tr>

</cfif>



<tr>
      <td bgcolor="#iif(form.step gt 6, de("ddddcc"), de("ffee99"))#" height="18">
                  <b class="labelstrong">&nbsp; 6) Confirmation</b>
      </td>
</tr>
<cfif form.step eq 6>
      <cfinclude template="_checkout_step6.cfm">
</cfif>

<tr>
      <td bgcolor="ffee99" height="18">
            <b class="labelstrong">&nbsp; 7) Receipt</b>
      </td>
</tr>
<cfif form.step eq 7>
<tr bgcolor="ffffcc">
      <td>
            <table border="0" cellpadding="10" cellspacing="0" width="100%">
                  <tr>
                        <td align="center"><font class="label" face="Arial,geneva,helvetica,sans-serif" size="2">
                        <br /><br />                  
                              Your order has been placed successfully.
                        <br /><br />
                        </font>
                        </td>
                  </tr>
            </table>      
      </td>
</tr>

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now