Skip to main content
Inspiring
November 30, 2012
Question

Multiple URL variables and cfMail

  • November 30, 2012
  • 1 reply
  • 3382 views

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>

    This topic has been closed for replies.

    1 reply

    Inspiring
    November 30, 2012

    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.

    wycksAuthor
    Inspiring
    December 1, 2012

    Thanks for the reply,

    Yeah, but I'm specifying the row to use in the user_accounts table in the URL... when I click "Post Reply" on one of the replies, it takes me down the page to the form (by using a named anchor) and the correct user_id shows in the URL like this:

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

    so the correct user_id shows up in the URL, but when I try to use it in the code I posted above, I'm only getting the information from the first row when, in this example, the information should be coming from the fourth row.

    BKBK
    Community Expert
    Community Expert
    December 1, 2012

    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.