We help IT Professionals succeed at work.

dynamic text not working in coldfusion

khaleghi
khaleghi used Ask the Experts™
on
I am trying to add a greeting to my website so after any user logged in they receive a greeting like Hi Andy
it is working when I design my page in ASP but in coldfusion the dynamic data disappears.
I am using Dreamweaver CS5 and am beginner in coding
can anybody tell me where is the problem.

<cfparam name="URL.Username" default="1">
<cfquery name="Recordset1" datasource="CFNB1" username="sa" password="123">
SELECT *
FROM dbo.Login
WHERE Username = <cfqueryparam value="#URL.Username#" cfsqltype="cf_sql_clob" maxlength="15"> 
</cfquery>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
<!--
body {
	font: 100%/1.4 Verdana, Arial, Helvetica, sans-serif;
	background: #42413C;
	margin: 0;
	padding: 0;
	color: #000;
}

/* ~~ Element/tag selectors ~~ */
ul, ol, dl { /* Due to variations between browsers, it's best practices to zero padding and margin on lists. For consistency, you can either specify the amounts you want here, or on the list items (LI, DT, DD) they contain. Remember that what you do here will cascade to the .nav list unless you write a more specific selector. */
	padding: 0;
	margin: 0;
}
h1, h2, h3, h4, h5, h6, p {
	margin-top: 0;	 /* removing the top margin gets around an issue where margins can escape from their containing div. The remaining bottom margin will hold it away from any elements that follow. */
	padding-right: 15px;
	padding-left: 15px; /* adding the padding to the sides of the elements within the divs, instead of the divs themselves, gets rid of any box model math. A nested div with side padding can also be used as an alternate method. */
}
a img { /* this selector removes the default blue border displayed in some browsers around an image when it is surrounded by a link */
	border: none;
}
/* ~~ Styling for your site's links must remain in this order - including the group of selectors that create the hover effect. ~~ */
a:link {
	color: #42413C;
	text-decoration: underline; /* unless you style your links to look extremely unique, it's best to provide underlines for quick visual identification */
}
a:visited {
	color: #6E6C64;
	text-decoration: underline;
}
a:hover, a:active, a:focus { /* this group of selectors will give a keyboard navigator the same hover experience as the person using a mouse. */
	text-decoration: none;
}

/* ~~ this fixed width container surrounds all other elements ~~ */
.container {
	width: 960px;
	background: #FFF;
	margin: 0 auto; /* the auto value on the sides, coupled with the width, centers the layout */
}

/* ~~ This is the layout information. ~~ 

1) Padding is only placed on the top and/or bottom of the div. The elements within this div have padding on their sides. This saves you from any "box model math". Keep in mind, if you add any side padding or border to the div itself, it will be added to the width you define to create the *total* width. You may also choose to remove the padding on the element in the div and place a second div within it with no width and the padding necessary for your design.

*/
.content {

	padding: 10px 0;
}

/* ~~ miscellaneous float/clear classes ~~ */
.fltrt {  /* this class can be used to float an element right in your page. The floated element must precede the element it should be next to on the page. */
	float: right;
	margin-left: 8px;
}
.fltlft { /* this class can be used to float an element left in your page. The floated element must precede the element it should be next to on the page. */
	float: left;
	margin-right: 8px;
}
.clearfloat { /* this class can be placed on a <br /> or empty div as the final element following the last floated div (within the #container) if the overflow:hidden on the .container is removed */
	clear:both;
	height:0;
	font-size: 1px;
	line-height: 0px;
}
-->
</style></head>

<body>

<div class="container">
  <div class="content">
    <h1>Hi<cfoutput>#Recordset1.FirstName#</cfoutput></h1>
    <!-- end .content --></div>
  <!-- end .container --></div>
</body>
</html>

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
ZvonkoSystems architect
Top Expert 2006

Commented:
It works for me so the problem is in the query lines.

Check this:

<cfparam name="URL.Username" default="1">
<cfquery name="Recordset1" datasource="CFNB1" username="sa" password="123">
SELECT *
FROM dbo.Login
WHERE Username = <cfqueryparam value="#URL.Username#" cfsqltype="cf_sql_clob" maxlength="15">
</cfquery>
<cfdump var="#Recordset1#" >

ZvonkoSystems architect
Top Expert 2006

Commented:
By the way, putting the "sa" account into page source is not the best idea.

Author

Commented:
Hi
This is the screenshot of what happened.
error2.jpg
ZvonkoSystems architect
Top Expert 2006

Commented:
Comeon, you see that Username is ?

Make this the first two lines:

<cfparam name="URL.Username" default="1">
<cfdump var="#URL.Username#" >

Most Valuable Expert 2015

Commented:
(no points please ...)

> This is the screenshot of what happened.

   The username value is "1".  That's probably not a valid username, which is why the results
   are empty.  Set URL.UserName to one of the values that exists in your database and it
   should work just fine.

> <cfqueryparam value="#URL.Username#" cfsqltype="cf_sql_clob" maxlength="15">

   It'll work either way, but the correct cfsqltype here is probably "cf_sql_varchar"


   

Author

Commented:
Dear Zvonko
this error comes:
Element MM_USERNAME is undefined in URL.

Author

Commented:
Dear aqx
>That's probably not a valid username
when I do this then dosen't matter who logs in the greeting will just say Hi Mum

Author

Commented:
Probably, the problem is my login page is in asp
because I am moving from asp to cfm
I have created a new login page with cfm to test,
but it never logs in
here's the code, hopefully helps.
<cfif IsDefined("FORM.Username")>
  <cfset MM_redirectLoginSuccess="LoginPass.asp">
  <cfset MM_redirectLoginFailed="LoginFail.asp">
  <cfquery  name="MM_rsUser" datasource="CFNB1" username="sa" password="123">
  SELECT Username,Password FROM dbo.Login WHERE Username=<cfqueryparam value="#FORM.Username#" cfsqltype="cf_sql_clob" maxlength="15"> AND Password=<cfqueryparam value="#FORM.Password#" cfsqltype="cf_sql_clob" maxlength="15">
  </cfquery>
  <cfif MM_rsUser.RecordCount NEQ 0>
    <cftry>
      <cflock scope="Session" timeout="30" type="Exclusive">
        <cfset Session.MM_Username=FORM.Username>
        <cfset Session.MM_UserAuthorization="">
      </cflock>
      <cfif IsDefined("URL.accessdenied") AND false>
        <cfset MM_redirectLoginSuccess=URL.accessdenied>
      </cfif>
      <cflocation url="#MM_redirectLoginSuccess#" addtoken="no">
      <cfcatch type="Lock">
        <!--- code for handling timeout of cflock --->
      </cfcatch>
    </cftry>
  </cfif>
  <cflocation url="#MM_redirectLoginFailed#" addtoken="no">
  <cfelse>
  <cfset MM_LoginAction=CGI.SCRIPT_NAME>
  <cfif CGI.QUERY_STRING NEQ "">
    <cfset MM_LoginAction=MM_LoginAction & "?" & XMLFormat(CGI.QUERY_STRING)>
  </cfif>
</cfif>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<cfprocessingdirective pageencoding="utf-8">
<title>Untitled Document</title>
<style type="text/css">
<!--
body {
	font: 100%/1.4 Verdana, Arial, Helvetica, sans-serif;
	background: #42413C;
	margin: 0;
	padding: 0;
	color: #000;
	background-image: url(image/Bg1.jpg);
}

/* ~~ Element/tag selectors ~~ */
ul, ol, dl { /* Due to variations between browsers, it's best practices to zero padding and margin on lists. For consistency, you can either specify the amounts you want here, or on the list items (LI, DT, DD) they contain. Remember that what you do here will cascade to the .nav list unless you write a more specific selector. */
	padding: 0;
	margin: 0;
}
h1, h2, h3, h4, h5, h6, p {
	margin-top: 0;	 /* removing the top margin gets around an issue where margins can escape from their containing div. The remaining bottom margin will hold it away from any elements that follow. */
	padding-right: 15px;
	padding-left: 15px; /* adding the padding to the sides of the elements within the divs, instead of the divs themselves, gets rid of any box model math. A nested div with side padding can also be used as an alternate method. */
}
a img { /* this selector removes the default blue border displayed in some browsers around an image when it is surrounded by a link */
	border: none;
}
/* ~~ Styling for your site's links must remain in this order - including the group of selectors that create the hover effect. ~~ */
a:link {
	color: #42413C;
	text-decoration: underline; /* unless you style your links to look extremely unique, it's best to provide underlines for quick visual identification */
}
a:visited {
	color: #6E6C64;
	text-decoration: underline;
}
a:hover, a:active, a:focus { /* this group of selectors will give a keyboard navigator the same hover experience as the person using a mouse. */
	text-decoration: none;
}

/* ~~ this fixed width container surrounds all other elements ~~ */
.container {
	width: 850px;
	background: #FFF;
	margin: 0 auto; /* the auto value on the sides, coupled with the width, centers the layout */
	background-image: url(image/Bg7.png);
}

/* ~~ This is the layout information. ~~ 

1) Padding is only placed on the top and/or bottom of the div. The elements within this div have padding on their sides. This saves you from any "box model math". Keep in mind, if you add any side padding or border to the div itself, it will be added to the width you define to create the *total* width. You may also choose to remove the padding on the element in the div and place a second div within it with no width and the padding necessary for your design.

*/
.content {

	padding: 10px 0;
}

/* ~~ miscellaneous float/clear classes ~~ */
.fltrt {  /* this class can be used to float an element right in your page. The floated element must precede the element it should be next to on the page. */
	float: right;
	margin-left: 8px;
}
.fltlft { /* this class can be used to float an element left in your page. The floated element must precede the element it should be next to on the page. */
	float: left;
	margin-right: 8px;
}
.clearfloat { /* this class can be placed on a <br /> or empty div as the final element following the last floated div (within the #container) if the overflow:hidden on the .container is removed */
	clear:both;
	height:0;
	font-size: 1px;
	line-height: 0px;
}
-->
</style></head>

<body>

<div class="container">
  <div class="content">
    <table width="850" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="170">&nbsp;</td>
        <td width="121">&nbsp;</td>
        <td width="272" height="435">&nbsp;</td>
        <td width="117">&nbsp;</td>
        <td width="170">&nbsp;</td>
      </tr>
      <tr>
        <td height="67">&nbsp;</td>
        <td>&nbsp;</td>
        <td><a href="Register.cfm"><img src="image/link1.png" width="76" height="58" border="0" /></a></td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td height="85">&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td height="119">&nbsp;</td>
        <td>&nbsp;</td>
        <td align="left"><form id="form1" name="form1" method="POST" action="<cfoutput>#MM_loginAction#</cfoutput>">
          <p>
            <label for="Username"></label>
            <input type="text" name="Username" id="Username" />
            <img src="image/Text7-2.png" alt="¿¿¿¿¿ ¿¿¿¿¿¿" width="70" height="38" align="absmiddle" />
            <label for="Password"></label>
            <input type="password" name="Password" id="Password" />
            <img src="image/Text8-2.png" alt="¿¿¿ ¿¿¿¿" width="70" height="38" align="absmiddle" /></p>
          <p>
            <input type="submit" name="submit" id="submit" value="¿¿¿¿" />
        </p>
        </form></td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td height="127">&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
    </table>
    <h1>&nbsp;</h1>
    <!-- end .content --></div>
<!-- end .container --></div>
</body>
</html>

Open in new window

Author

Commented:
the login problem solved
I have created a application.cfm page with this code
<cfapplication name="GetLeadApp"
sessionmanagement="Yes"
sessiontimeout=#CreateTimeSpan(0,0,45,0)#>

but the dynamic data still not working
Most Valuable Expert 2015

Commented:
On the redirect page you mean? I suspect the code isn't adding the username parameter to the redirect url ie  ?username=#form.username#

ie   If your "success" page is expecting URL.userName, then this line:
      <cfset MM_redirectLoginSuccess="LoginPass.asp">

Should probably be something like:
       <cfset MM_redirectLoginSuccess="LoginPass.asp?username"& form.username>


But frankly the automated DW code is *awful*.  Personally, I always recommend people DON'T use it and instead write their own.  It's bound to be better written, and at least you'll be able to understand it!   The DW stuff is nearly unintelligible ... ;-)

Author

Commented:
>DW stuff is nearly unintelligible
oh my goodness, I decided to move from ASP to CFM because Adobe says DW is completely supporting this language
if it gonna be a big trouble then probably it's better to come back to ASP

>Should probably be something like:
       <cfset MM_redirectLoginSuccess="LoginPass.asp?username"& form.username>
no gain

thanks
Most Valuable Expert 2015

Commented:
>> then probably it's better to come back to ASP

   No, you misunderstand.  ANY code "automatically generated by wizards", be it for
   ASP, PHP, CF, SQL, Java, etc..., is almost never as good code you write yourself.  They're too
   generic and are notoriously overly verbose.  Wizards really shouldn't be used as substitute
   for knowing how to program in a specific language.  Granted some people do use them
   that way, but it only gets you so far ... ie It's a lot harder to debug problems when you didn't
   write the code and don't understand it.  

> no gain

   Are we still talking about the same issue: ie The same user name shows up every time?
ZvonkoSystems architect
Top Expert 2006

Commented:
I can only cofirm _agx_ statements about MM_ scripts: I hate them.

But let me ask why you use ASP for login at all?
Look here: http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7db9.html

I can show you how to transfer all ASP statements (ADO, AD LDAP) to CF but first on Monday.

If _agx_ has an example by hand then go on.

For example: the username and password fields do have a prefix j_ when submitted from CF login page. That means it is very tricky but when you worked it out once then you have always a template for your domain.


Author

Commented:
>The same user name shows up every time?
it's worth than it , no dynamic data shows at all

Author

Commented:
>I can show you how to transfer all ASP statements (ADO, AD LDAP) to CF but first on Monday
that's very good,  I will wait

Commented:
Hi khaleghi,
the Solution is quite simple:

If you send yout form with POST method you should ask in the processing Page for FORM.variable instead of URL.variable, otherways if you send it with get you take URL.xxx instead of FORM.xxxx  

Try it

Author

Commented:
Dear, dagaz_de
the result is same,  no dynamic data shows
have a look on these codes,  it's quite simple,  why not working?
<cfparam name="FORM.Username" default="1">
<cfquery name="Recordset1" datasource="CFNB1" username="sa" password="123">
SELECT *
FROM dbo.Login
WHERE Username = <cfqueryparam value="#FORM.Username#" cfsqltype="cf_sql_clob" maxlength="15"> 
</cfquery>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
  <div>
    <h1>Hi<cfoutput>#Recordset1.FirstName#</cfoutput></h1>
    </div>
  
</body>
</html>

Open in new window

Most Valuable Expert 2015

Commented:
The variable scope isn't the problem.  I suspect you're not passing ANY parameter to this page.  Unless you pass a parameter to this page, the default username "1" will ALWAYS be used

ie   <cfparam name="URL.Username" default="1">

It's doubtful "1" is actually a username in your table. That's why your query doesn't return any records and why the output doesn't display a name.  

However you arrive at this page, you have to use a valid username in the query. If you're redirecting the user via CFLOCATION, then pass the desired username as a URL parameter

<cflocation url="theNameOfYourGreetingPage.cfm?username=#someUserNameHere#">

... or if you stored the username in the SESSION scope already, use the session variable in the query.  

<cfquery name="Recordset1" datasource="CFNB1" username="sa" password="123">
SELECT  FirstName
FROM      Login
WHERE   Username = <cfqueryparam value="#session.Username#" cfsqltype="cf_sql_varchar" maxlength="15">
</cfquery>


The exact code depends on HOW the user arrives at this page.  So if you need more assistance, please post the code showing how the user is redirected to your "greeting page".

Author

Commented:
Dear agx
thanks, so much
my web homepage is a Login page and then users redirects to a greeting page also after that they may go to their profile page,  
So after logging in the user should be identified everywhere.

This is the login page codes
thanks again.
<cfquery name="Recordset1" datasource="CFNB1" username="sa" password="123">
SELECT *
FROM dbo.Login 
</cfquery>
<cfif IsDefined("FORM.Username")>
  <cfset MM_redirectLoginSuccess="welcom.cfm">
  <cfset MM_redirectLoginFailed="LoginFail.asp">
  <cfquery  name="MM_rsUser" datasource="CFNB1" username="sa" password="123">
  SELECT Username,Password FROM dbo.Login WHERE Username=<cfqueryparam value="#FORM.Username#" cfsqltype="cf_sql_clob" maxlength="15"> AND Password=<cfqueryparam value="#FORM.Password#" cfsqltype="cf_sql_clob" maxlength="15">
  </cfquery>
  <cfif MM_rsUser.RecordCount NEQ 0>
    <cftry>
      <cflock scope="Session" timeout="30" type="Exclusive">
        <cfset Session.MM_Username=FORM.Username>
        <cfset Session.MM_UserAuthorization="">
      </cflock>
      <cfif IsDefined("URL.accessdenied") AND false>
        <cfset MM_redirectLoginSuccess=URL.accessdenied>
      </cfif>
      <cflocation url="#MM_redirectLoginSuccess#" addtoken="no">
      <cfcatch type="Lock">
        <!--- code for handling timeout of cflock --->
      </cfcatch>
    </cftry>
  </cfif>
  <cflocation url="#MM_redirectLoginFailed#" addtoken="no">
  <cfelse>
  <cfset MM_LoginAction=CGI.SCRIPT_NAME>
  <cfif CGI.QUERY_STRING NEQ "">
    <cfset MM_LoginAction=MM_LoginAction & "?" & XMLFormat(CGI.QUERY_STRING)>
  </cfif>
</cfif>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<cfprocessingdirective pageencoding="utf-8">
<title>Untitled Document</title>
<style type="text/css">
<!--
body {
	font: 100%/1.4 Verdana, Arial, Helvetica, sans-serif;
	background: #42413C;
	margin: 0;
	padding: 0;
	color: #000;
	background-image: url(image/Bg1.jpg);
}

/* ~~ Element/tag selectors ~~ */
ul, ol, dl { /* Due to variations between browsers, it's best practices to zero padding and margin on lists. For consistency, you can either specify the amounts you want here, or on the list items (LI, DT, DD) they contain. Remember that what you do here will cascade to the .nav list unless you write a more specific selector. */
	padding: 0;
	margin: 0;
}
h1, h2, h3, h4, h5, h6, p {
	margin-top: 0;	 /* removing the top margin gets around an issue where margins can escape from their containing div. The remaining bottom margin will hold it away from any elements that follow. */
	padding-right: 15px;
	padding-left: 15px; /* adding the padding to the sides of the elements within the divs, instead of the divs themselves, gets rid of any box model math. A nested div with side padding can also be used as an alternate method. */
}
a img { /* this selector removes the default blue border displayed in some browsers around an image when it is surrounded by a link */
	border: none;
}
/* ~~ Styling for your site's links must remain in this order - including the group of selectors that create the hover effect. ~~ */
a:link {
	color: #42413C;
	text-decoration: underline; /* unless you style your links to look extremely unique, it's best to provide underlines for quick visual identification */
}
a:visited {
	color: #6E6C64;
	text-decoration: underline;
}
a:hover, a:active, a:focus { /* this group of selectors will give a keyboard navigator the same hover experience as the person using a mouse. */
	text-decoration: none;
}

/* ~~ this fixed width container surrounds all other elements ~~ */
.container {
	width: 850px;
	background: #FFF;
	margin: 0 auto; /* the auto value on the sides, coupled with the width, centers the layout */
	background-image: url(image/Bg7.png);
}

/* ~~ This is the layout information. ~~ 

1) Padding is only placed on the top and/or bottom of the div. The elements within this div have padding on their sides. This saves you from any "box model math". Keep in mind, if you add any side padding or border to the div itself, it will be added to the width you define to create the *total* width. You may also choose to remove the padding on the element in the div and place a second div within it with no width and the padding necessary for your design.

*/
.content {

	padding: 10px 0;
}

/* ~~ miscellaneous float/clear classes ~~ */
.fltrt {  /* this class can be used to float an element right in your page. The floated element must precede the element it should be next to on the page. */
	float: right;
	margin-left: 8px;
}
.fltlft { /* this class can be used to float an element left in your page. The floated element must precede the element it should be next to on the page. */
	float: left;
	margin-right: 8px;
}
.clearfloat { /* this class can be placed on a <br /> or empty div as the final element following the last floated div (within the #container) if the overflow:hidden on the .container is removed */
	clear:both;
	height:0;
	font-size: 1px;
	line-height: 0px;
}
-->
</style></head>

<body>

<div class="container">
  <div class="content">
    <table width="850" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="170">&nbsp;</td>
        <td width="121">&nbsp;</td>
        <td width="272" height="435">&nbsp;</td>
        <td width="117">&nbsp;</td>
        <td width="170">&nbsp;</td>
      </tr>
      <tr>
        <td height="67">&nbsp;</td>
        <td>&nbsp;</td>
        <td><a href="Register.cfm"><img src="image/link1.png" width="76" height="58" border="0" /></a></td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td height="85">&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td height="119">&nbsp;</td>
        <td>&nbsp;</td>
        <td align="left"><form id="form1" name="form1" method="POST" action="<cfoutput>#MM_loginAction#</cfoutput>">
          <label for="Username2">Username</label>
          <input type="text" name="Username" id="Username2" />
          <label for="Password">Password</label>
          <input type="text" name="Password" id="Password" />
          <input type="submit" name="Submit" id="Submit" value="Submit" />
        </form></td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td height="127">&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
    </table>
    <h1>&nbsp;</h1>
    <!-- end .content --></div>
<!-- end .container --></div>
</body>
</html>

Open in new window

Most Valuable Expert 2015
Commented:
There's at least 3 ways to handle it ... use any _one_ of them

>>> <cfset MM_redirectLoginSuccess="welcom.cfm">

Option #1) If the login is successful the user will be redirected to that page.  Just add the username parameter to the URL.

ie  <cfset MM_redirectLoginSuccess="welcom.cfm?username=#FORM.userName#">

... and make sure your welcome page uses the URL scope *not* the FORM scope. ie

<cfparam name="URL.Username" default="1">
<cfquery name="Recordset1" datasource="CFNB1" username="sa" password="123">
SELECT FirstName
FROM    Login
WHERE Username = <cfqueryparam value="#URL.Username#" cfsqltype="cf_sql_sqlvarchar" maxlength="15">
</cfquery>

>>> <cfset Session.MM_Username=FORM.Username>

Option #2) OR since you're already storing the username in a session variable, just use the session variable in your query

WHERE Username = <cfqueryparam value="#session.Session.MM_Username#" cfsqltype="cf_sql_sqlvarchar" maxlength="15">


Option #3) OR ... retrieve the "FirstName" in your original query. Then store the "FirstName" in a session variable.

<cfquery  name="MM_rsUser" datasource="CFNB1" username="sa" password="123">
  SELECT Username,Password, FirstName  ... etc....
</cfquery>
..... etc..
 <cfset Session.MM_FirstName=MM_rsUser.FirstName>
 <cfset Session.MM_Username=FORM.Username>
..... etc..

Then you can skip the query on the welcome page and just use the session variable instead.

         <h1>Hi<cfoutput>#session.MM_FirstName#</cfoutput></h1>





Most Valuable Expert 2015

Commented:
But like I said, I don't use the "wizard" scripts. You're better off writing your own.

Author

Commented:
Option1#
with this way I can see the user's first name just in the first page after logging in, in any inner page I can't have dynamic data.

Option2#
by this way no dynamic data appears on the welcome page.

thanks
Most Valuable Expert 2015

Commented:
>>> with this way I can see the user's first name just in the first page after logging in,
>> in any inner page I can't have dynamic data.

I don't understand your response. Your initial question was how to display the firstName on the welcome page (only).  I think we've already answered this question.  If you want to display the same "username" on other pages (not just the welcome page), you should use option #3.


>> by this way no dynamic data appears on the welcome page.

Logically, if option #1 works then option #2 must work as well because both use the same "username" value. If it doesn't work correctly for you, you probably didn't implement the code correctly.

>> by this way no dynamic data appears on the welcome page.

This sounds like the same problem we covered already.  If the query on the welcome page doesn't return any records, it means the "userName" wasn't found. So of course the "firstName" is not displayed.  You can't display a record that doesn't exist ;-)  You need to do some basic debugging to see where you went wrong.  The exact same way you did before.  Dump the query and "username" value. ie See why it's not returning any records. Most likely the username value is missing or invalid.

But as I already mentioned, you only need to implement ONE of the options, not all three.

Author

Commented:
then lets just talk about option 3

I'm not sure if I undrestood well ,
I've added this code to the top of the login page:
<cfquery  name="MM_rsUser" datasource="CFNB1" username="sa" password="123">
  SELECT  Firstname from dbo.login
</cfquery>
<cfset Session.MM_FirstName=MM_rsUser.FirstName>


and I added this code anywhere in any page that I whish to have a dynamic name
<cfoutput>#session.MM_FirstName#</cfoutput>

so
something is missing here because all the time just the first record of the database is read then if any user log in to the site it will just say Hi mummy

Most Valuable Expert 2015

Commented:
>> I'm not sure if I undrestood well ,

Yeah, I think you misunderstood.  If you look at your login page, that's where your session variables are created.  That's where you should create the new one (MM_FirstName) too.  

This goes back to what I was saying about understanding what any "wizard" code is doing. On the login page, the code runs a query named #MM_rsUser# to verify the username/password submitted.  Now look at the SELECT list. Notice it doesn't retrieve the "FirstName" column?  You have to *add* that column to the query so you can use it later on.

        SELECT Username,Password FROM  .... etc....

Later on in the login page code it sets two session variables if the login is verified.  This is where you would set the variable of your new variable Session.MM_FirstName

        <cfset Session.MM_Username=FORM.Username>
        <cfset Session.MM_UserAuthorization="">
        <!---- cfset your new variable here --->

Once you've created the session variable, you can use it on any page.

Author

Commented:
Thank you
I just can say THANK YOU
and promise to learn codes more and more.
Most Valuable Expert 2015

Commented:
You're welcome, and don't worry about not knowing everything at first. An honest desire to learn is more important. Most experts love helping people "with a yearn to learn" :)