Friday, March 19, 2010
I got two simple coldfusion tips for you.
1. Tip #1: See my previous post about Coldfusion issue when if you use SELECT * in your cfquery and then say you add a row to that table. That changes the query because you have now added another row for CF to grab. Apparently, CF doesn’t like that at all. It throws an error. All you have to do to fix the issue is Restart Coldfusion and then your site should be back up. I know it sucks, i shouldn’t have to restart CF when i add a new column to my table. Seems silly. And, I know SELECT * is not the correct or best way to write your query. You should always write out all of the columns and rows from all of the tables you are querying. The reason I am using SELECT * is because I want this query to work across multiple sites under different domains. I don’t want to have to go back and change every single query when i add a new column. That’s why i am doing it this way. One other added piece of information i should add here is that the error from coldfusion only occurs when you use cfqueryparam in your queries. CF must cache the query.
2. Tip #2: IF you have a Thankyou page that appears after you submit a form and you want to lock the page down be sure to add this little snippet of code at the top of your page. Say you have a form that accepts FirstName, LastName and EmailAddress. All of these are required. Pick one (or more) of the fields. At the very top of your page put this code:
<cfif NOT IsDefined(‘form.FirstName’)>
<cflocation url=“index.cfm” addtoken=“no”>
IF someone comes to the page and they try to see what you got without submitting your form they will get redirected to your homepage. Also, wrap the form.FirstName variable in single quotes. You need those. If you don’t use those, you will get a coldfusion error.
Hope this helps someone out there.