Skip navigation
Currently Being Moderated

Multiple URL variables and cfMail

Nov 30, 2012 10:02 AM

Hi,

 

I posted this on the bottom of a different discussion I posted (Passing two URL variables) where my problem was solved.  But now that I know how to pass two URL variables, I'm having trouble putting one of those variables to use.

 

I'm working on a page like this:

     http://mymindsnotright.com/discussionGenReplies.cfm?post_id=22

 

and i'm trying to set it up so, when I click a 'post reply' link, an email is sent to the original poster and the person whose reply you clicked 'post reply' on.  The idea was to use URL variables, so (as you  can see on the page i linked above) when I click a post reply link, the user_id of the person who posted the reply that i'm replying to shows up in the URL like this:

     http://mymindsnotright.com/discussionGenReplies.cfm?post_id=22&user_id =4#replytest

 

but for some reason the user_id in the URL isn't being used and instead it's just using the information from the first row in the table--even though the correct user_id is being shown in the URL

 

Here's what I'm working with:

====================================================================

<cfparam name="URL.post_id" default="1">

<cfset CurrentPage=GetFileFromPath(GetBaseTemplatePath())>

<cfparam name="URL.user_id" default="1">

<cfparam name="FORM.post_id" default="1">

<cfquery name="rsGenPost" datasource="mymindsnotrighttest" username="mikewycklendt" password="Mex0Wix0">

SELECT *

FROM boardtopics

WHERE post_id = <cfqueryparam value="#URL.post_id#" cfsqltype="cf_sql_numeric">

</cfquery>

<cfquery name="rsTopicInfoForEmail" datasource="mymindsnotrighttest" username="mikewycklendt" password="Mex0Wix0">

SELECT *

FROM boardtopics

WHERE post_id = <cfqueryparam value="#FORM.post_id#" cfsqltype="cf_sql_numeric">

</cfquery>

<cfquery name="rsReplyToReplyEmail" datasource="mymindsnotrighttest" username="mikewycklendt" password="Mex0Wix0">

SELECT *

FROM user_accounts

WHERE user_id = <cfqueryparam value="#URL.user_id#" cfsqltype="cf_sql_numeric">

</cfquery>

 

 

 

 

 

 

<cfif IsDefined("FORM.MM_InsertRecord") AND FORM.MM_InsertRecord EQ "form1">

  <cfquery datasource="mymindsnotrighttest" password="Mex0Wix0" username="mikewycklendt">

  INSERT INTO board_replies (reply_id, post_id, board_id, user_id, username, title, content, date)

VALUES (<cfif IsDefined("FORM.reply_id") AND #FORM.reply_id# NEQ "">

<cfqueryparam value="#FORM.reply_id#" cfsqltype="cf_sql_numeric">

<cfelse>

NULL

</cfif>

, <cfif IsDefined("FORM.post_id") AND #FORM.post_id# NEQ "">

<cfqueryparam value="#FORM.post_id#" cfsqltype="cf_sql_numeric">

<cfelse>

NULL

</cfif>

, <cfif IsDefined("FORM.board_id") AND #FORM.board_id# NEQ "">

<cfqueryparam value="#FORM.board_id#" cfsqltype="cf_sql_numeric">

<cfelse>

NULL

</cfif>

, <cfif IsDefined("FORM.user_id") AND #FORM.user_id# NEQ "">

<cfqueryparam value="#FORM.user_id#" cfsqltype="cf_sql_numeric">

<cfelse>

NULL

</cfif>

, <cfif IsDefined("FORM.username") AND #FORM.username# NEQ "">

<cfqueryparam value="#FORM.username#" cfsqltype="cf_sql_clob" maxlength="65535">

<cfelse>

''

</cfif>

, <cfif IsDefined("FORM.title") AND #FORM.title# NEQ "">

<cfqueryparam value="#FORM.title#" cfsqltype="cf_sql_clob" maxlength="65535">

<cfelse>

''

</cfif>

, <cfif IsDefined("FORM.content") AND #FORM.content# NEQ "">

<cfqueryparam value="#FORM.content#" cfsqltype="cf_sql_clob" maxlength="2147483647">

<cfelse>

''

</cfif>

, <cfif IsDefined("FORM.date") AND #FORM.date# NEQ "">

<cfqueryparam value="#FORM.date#" cfsqltype="cf_sql_timestamp">

<cfelse>

NULL

</cfif>

)

<cfquery name="rsEmail" datasource="mymindsnotrighttest" username="mikewycklendt" password="Mex0Wix0">

SELECT *

FROM user_accounts

WHERE user_id = <cfoutput>#rsTopicInfoForEmail.user_id#</cfoutput>

</cfquery>

 

 

<cfquery name="rsEmailtoReply" datasource="mymindsnotrighttest" username="mikewycklendt" password="Mex0Wix0">

SELECT *

FROM user_accounts

WHERE user_id = <cfoutput>#rsReplyToReplyEmail.user_id#</cfoutput>

</cfquery>

 

 

<cfmail

        TO="mikewycklendt@gmail.com"

        from="mikewycklendt@mymindsnotright.com"

        subject="#FORM.username#"

        server="scriptmail.intermedia.net"

        >#FORM.username# has replied to your post (#rsTopicInfoForEmail.title#)

-------------------------------------------------

 

 

You can see the reply by clicking this link:

http://www.mymindsnotright.com/discussionGenReplies.cfm?post_id=#FORM. post_id#

 

should send to:  #rsEmail.user_email#

and a reply to #rsEmailToReply.username# reply who has the email:

#rsEmailToReply.user_email#

 

  </cfmail>

 

 

 

 

 

 

 

 

 

 

 

 

  </cfquery>

  <cflocation url="discussionGenReplies.cfm?post_id=#FORM.post_id#">

</cfif>

 

 

<cfquery name="rsGenReplies" datasource="mymindsnotrighttest" username="mikewycklendt" password="Mex0Wix0">

SELECT *

FROM board_replies

WHERE post_id = <cfqueryparam value="#URL.post_id#" cfsqltype="cf_sql_numeric">

ORDER BY reply_id ASC

</cfquery>

<cfquery name="rsReplyRecordCount" datasource="mymindsnotrighttest" username="mikewycklendt" password="Mex0Wix0">

SELECT *

FROM board_replies

</cfquery>

 
Replies
  • Currently Being Moderated
    Nov 30, 2012 12:02 PM   in reply to wycks

    I glanced through the code but let's focus on this statement:  "but for some reason the user_id in the URL isn't being used and instead it's just using the information from the first row in the table--even though the correct user_id is being shown in the URL"

     

    When you get data from a query object without specifying the row number, you get data from the first row.  That is probably what is happening to you.

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 1, 2012 11:20 AM   in reply to wycks

    Remove the line <cfparam name="URL.user_id" default="1"> and see if it helps. I say this because it looks like your link has a space just after user_id.

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 1, 2012 12:41 PM   in reply to wycks

    I was guessing that the variable url.user_id was the one coming from the cfparam tag, and not the one from the URL. The error message confirms this. In your code, there is a space where I have put *. It just might be the cause of the error. Remove the space, save the file and try again.

     

    http://mymindsnotright.com/discussionGenReplies.cfm?post_id=22&user_id*=4#replytest

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 2, 2012 12:45 AM   in reply to wycks

    OK, that rules that out. For the next test, change the cfparam line to <cfparam name="URL.user_id" default="5">. Add the line <cfdump var="#url#"> just before the query rsReplyToReplyEmail. Repeat the calls or open the pages in the usual order. That is, with the value user_id=4 in the query-string. Which URL variables are dumped?

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 2, 2012 7:55 AM   in reply to wycks

    That clearly says that you are not arriving at the page by the URL you think you are. That is, you are not arriving at the page by http://mymindsnotright.com/discussionGenReplies.cfm?post_id=22&user_id =4#replytest .

     

    I would now hazard another guess. You should add appropriate URL variables to the action in the line:

     

    <form method="post" name="form1" action="#currentTemplateRelativePath#">

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 2, 2012 8:41 AM   in reply to wycks

    wycks wrote:

     

    When I made the change you suggested, i get the error:

    Variable CURRENTTEMPLATERELATIVEPATH is undefined.

     

    My apologies. I just copied the first form tag at hand. The variable currenttemplaterelativepath was a suggestion of my own. We have moved on since then.

     

    I believe you now use <form method="post" name="form1" action="#CGI.SCRIPT_NAME#">. So, add the appropriate URL variables to that.

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 2, 2012 9:52 AM   in reply to wycks

    yes.

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 3, 2012 9:33 AM   in reply to wycks

         http://localhost:8500/Htdocs/discussionGenReplies.cfm?post_id=10&CFID= 4900&CFTOKEN=36760993

    The main problem is, there are too many factors changing at the same time. Now there are CFID and CFToken in the URL. This raises the question how you have set up your application.

     

    You should not append session tokens to the URL. Instead, use in your application file, settings like the following:

     

    applicationTimeout = "#createTimespan(1,0,0,0)#"

    sessionmanagement = "true"

    sessionTimeout = "#createTimespan(0,0,20,0)#"

    setClientCookies = "true"

    I changed the form1 action to this:

             <cfform method="post" name="form1" action="#CGI.SCRIPT_NAME#?post_id=#rsGenReplies.post_id#&user_id=#rsR eplyToReplyEmail.user_id#">

     

    I also tried this:

             <cfform method="post" name="form1" action="#CGI.SCRIPT_NAME#?post_id=#rsGenReplies.post_id#&user_id=#rsU RL.user_id#">

     

    and the cf dump still sticks with the user_id variable defined near the top of the page.

     

    Also, after submitting the form, this is the URL that returns:

         http://localhost:8500/Htdocs/discussionGenReplies.cfm?post_id=10&CFID= 4900&CFTOKEN=36760993

     

    shouldn't there be a user)id variable in that URL after submitting the form with the new form1 action?

    Indeed, user_id should appear in the URL when you submit the form <cfform method="post" name="form1" action="#CGI.SCRIPT_NAME#?post_id=#rsGenReplies.post_id#&user_id=#rsU RL.user_id#">. To debug this, place the following line just before the form tag:

     

    <p>Action: <cfoutput>#CGI.SCRIPT_NAME#?post_id=#rsGenReplies.post_id#&user_id=#r sURL.user_id#</cfoutput></p>

     

    What is the output?

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 3, 2012 11:40 PM   in reply to wycks
    Action: /Htdocs/discussionGenReplies.cfm?post_id=10&user_id=

     

    Precisely what I was after. That tells me there is no value for rsReplyToReplyEmail.user_id. Verify the query rsReplyToReplyEmail and the data.

     

    My gut feeling is that something is missing from the setting of user_id. I have walked through the page. When the page opens initially, cfparam sets the default value. This value is the basis for the query rsReplyToReplyEmail. Presumably, the query supplies a new value for the user_id, namely,  rsReplyToReplyEmail.user_id. Is this user_id different from the one in the where-clause of the query?

     

    If they are the same, then there is duplication in the code. That will have to be fixed. If they are different, then there is inconsistency in the code. That will also have to be fixed.

     

    Now that rsReplyToReplyEmail.user_id has entered the food chain, it reappears as the URL variable, user_id,  in the action of the form. That value is recycled back to the main page when the form is submitted. It then goes back to being the user_id in the where-clause of the query rsReplyToReplyEmail. That is a cycle that keeps rotating the same value of user_id.

     

    You have to break it by introducing the real user_id. At some point this user ID has to replace the default ID set by cfparam. I remember suggesting some days ago that you use, for example, getAuthUser() to identify the actual user. You could then use the username in the where-clause of the query.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points