Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CFLOCATION after a INSERT statement 2

Status
Not open for further replies.

ChiefJoseph

Programmer
Feb 16, 2001
44
US
Hey I swear i read about this on a previous question but i cant find it,

heres the code:


<CFQUERY NAME=&quot;InsertMessage&quot; DATASOURCE=&quot;mydb&quot; DBTYPE=&quot;ODBC&quot;>
INSERT INTO UserMessage (
stuff...
)
VALUES (
stuff...
)
</CFQUERY>

<CFLOCATION URL=&quot;RecordGet.cfm&quot;>
</BODY>

heres the deal, it inserts the information fine. but gives me an error with my variables when i add the CFLOCATION

The help would be appriciated
 
hey ChiefJoseph!

I need some more info. What does recordGet.cfm do? Where do the variables you're putting into your query come from?

Also, are these form variables or URL ?

thanks
 
Hey Chief,

Is the error occuring on the script which contains the insert and the cflocation tag or does it occur on the &quot;RecordGet.cfm&quot; page? If your browser's location shows &quot;../recordget.cfm&quot; then it would appear that the code you posted above is working fine and the error is occuring on the other script. It the other script expects certain parameters to be passed to it, you'll need to pass these through the <cflocation> tag like this:

<cflocation url=&quot;RecordGet.cfm?var1=#urlencodedformat(var1)#&var2= .... &quot;>

Hope this helps,
GJ
 
OK heres a little more,

RecordGet.cfm is a page that has a simple SELECT statement that gets messages, and a FORM that allows that includes a textbox that when submited sends the variables to the InsertMessage.cfm which inserts the submited info to the database then redirecting them back to RecordGet.cfm so they see there post.

Now my question that might solve my CFLOCATION error. as you can see the InsertMessage.cfm doesn't even give a GUI to the user. Its just the middle man. This is in my opionion very LAME!!! It seems like there could be a way to redirect the submit button to call a function that will do my insert then reload the page. Or maybe a if statement that doe's somewhat the same thing?

This cant be that hard of a problem, I mean this bbs basically is what im trying to simulate(Its the best page of its kind that i've found)

Thanks for you help guys

ps. the error only occurs when i add the CFLOCATION but the error doesn't seem to do anything because the insert statement add the info anyway!
 
This is a good assumption.

>>>It seems like there could be a way to redirect the submit button to call a function that will do my insert then reload the page. Or maybe a if statement that does somewhat the same thing?<<<

What you need is URL parameters. First, CFPARAM so you know that the variable at least exists. Then, CFIF this url.variable is not 0 run the insert query and then cflocation the same page, without any URL parameters.

The form action passes the url.variable, which is cleared every time the insert statement is executed. The form parameters are passed to the same page, but the CFLOCATION wipes everything and starts over.


This is just the basics, but I hope it moves you to the next problem at least.

<CFPARAM name=&quot;url.flag&quot; default=0>


<CFIF url.flag NEQ 0>
<!--- only happens if form was submitted --->
<CFQUERY>
insert into TABLE
(
name,text
)
values
(
'#form.udname#','#form.udtext#'
)
</CFQUERY>
<CFLOCATION url = &quot;recordGet.cfm&quot;>
</CFIF>

<!--- always happens is url.flag is 0 --->
<CFQUERY name=&quot;getMessages&quot; datasource=&quot;#ds#&quot;>
</CFQUERY>

<form name=&quot;x&quot; action=&quot;recoredGet.cfm?flag=1&quot; method=&quot;post&quot;>

Name:<br>
<input type=&quot;text&quot; name=&quot;udName&quot; size=&quot;20&quot;><br><br>

Text:<br>
<textarea name=&quot;udText&quot; cols=&quot;30&quot; rows=&quot;7&quot;></textarea>

<br>
Existing messages<br>
<table width=&quot;100%&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; border=&quot;0&quot; bordercolor=&quot;CCCCCC&quot;>
<tr>
<td>Name</td>
<td>Text</td>
</tr>
<CFOUTPUT query=&quot;getMessages&quot;>
<tr>
<td>#name#</td>
<td>#text#</td>
</tr>
</CFOUTPUT>
</table>
</form>
 
Once again strantheman shows me the light!!
You guys are brilliant. Thanks a ton(you too gunjack).

You know, working with C++, Perl, and other object oriented languages I immediately tried to use this programming pattern with CF. I guess when I get to more complicating programs I'll learn where to use it.

Thanks again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top