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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems with my blog app 1

Status
Not open for further replies.

markso

Technical User
Joined
Jul 3, 2002
Messages
827
Location
GB
I'm designing a web log app as a means of geting to grips with CF (only locally at the moment).

Basically I post articles up and people are invited to reply with comments (for which they have to register & login etc). I set up my database with 3 tables - articles, comments and users. The articles table has a one to many relationship with the comments table via an articleID foreign key. I'm having 2 problems with the adding comments bit:

1. How do I set up the add a comment page so that it forces people to register or login first? I want (obviously) people to read without logging in. I've set up a basic application.cfm, but I guess this isn't the place to do this otherwise people will need to login before viewing any pages.

2. how do I set up the add a comment form to ensure the posted comment gets viewed with the original article, bearing in mind how I set the dbase up.

Any info gratefully recieved

Cheers

Mark
 
Your answers:

1. Using cookies for this is ok, but you can use session variables if you wish...

An easy way to use these is to check the cookie or the session var against the db, if it matches, let the user see the post page... and do the same thing on the db insert post page... Basically

..login query against cookies..
..if user login is correct..
.. if action button not clicked ..
..show post page..
..action button clicked...
..db insert page..
..if user login incorrect..
..show login form that resets cookie..

That should do ya...


2. Hidden field.. no matter your db setup, you have to have a post id for your reply.. So set this in a hidden id in your form..

Does this help?

tony Did I help?
Vote!
 
Tony,

Thanks for that. You confirmed my suspicions about using the hidden field in the form.

Will try the cookies option and let you know

Mark
 
Thanks for the vote... Did I help?
Vote!
 
OK Tony, that all worked, but I now have another problem, this time displaying the comments that relate to the articles in my detail page. As I explained above my commentID is linked to the articleID in the d/base with a one to many article to comment relationship. The d/base has things showing correctly, but my cfquery only returns comments when the commentID is exactly the same as the article ID (i.e commentID and article ID both =5

Here's my query code.

<cfquery name=&quot;EntryDetail&quot; datasource=&quot;myapps&quot; maxrows=1>
SELECT blogArticles.articleID, blogArticles.articleIntro, blogArticles.articleDate, blogArticles.article, comments.commentID, comments.commentDate, comments.comment
FROM blogArticles, comments
WHERE comments.commentID = blogArticles.articleID
<cfif IsDefined(&quot;URL.ID&quot;)>
WHERE blogArticles.articleID = #Val(URL.ID)#
</cfif>
</cfquery>

I'm assuming I've missed something obvious!

Mark
 
it would seem to need be more like this...


<cfquery name=&quot;EntryDetail&quot; datasource=&quot;myapps&quot; maxrows=1>
SELECT blogArticles.articleID, blogArticles.articleIntro, blogArticles.articleDate, blogArticles.article, comments.commentID, comments.commentDate, comments.comment
FROM blogArticles, comments
WHERE comments.articleID = blogArticles.articleID
<cfif IsDefined(&quot;URL.ID&quot;)>
WHERE blogArticles.articleID = #Val(URL.ID)#
</cfif>
</cfquery> ALFII.com
 
* where articleID is the relational field to well... the idea of the article... commentID SHOULD BE a unique ID strictuly for the comments table... ALFII.com
 
Yep, that was a typo on my part, it should have been comments.articleID. However, I'm getting the following error message now:

[MERANT][SequeLink JDBC Driver][ODBC Socket][Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'comments.articleID = blogArticles.articleID WHERE blogArticles.articleID = 5'.
 
change:

<cfif IsDefined(&quot;URL.ID&quot;)>
WHERE blogArticles.articleID = #Val(URL.ID)#
</cfif>

to

<cfif IsDefined(&quot;URL.ID&quot;)>
AND blogArticles.articleID = #Val(URL.ID)#
</cfif> ALFII.com
 
Cheers again Tony, that cracked it. All I have to do now is design the UI (the easy bit!)and I'll be there.

Mark
 
Hey! You need a tip or two, you know what forum to come to...

-or-

thicks@wisernet.com will get ahold of me if you like.

Tony ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
Tony, just a quick question. Am I better off using my cfm files as cfincludes in html files rather than trying to modify what I've done with all the HTML stuff (css and the like). It would appear the better and quicker solution to me but would just like some confirmation.

Ta

Mark
 
If you mean having a header and footer file and doing something like...

index.cfm:
----------
<CFINCLUDE template=&quot;header.cfm&quot;>
...content...
<CFINCLUDE template=&quot;footer.cfm&quot;>

This takes up a lot less space as you can tell and is easier to maintain but if this is the path you are taking a simpler way would be to create application.cfm in your site's root directory and give it the contents:

<CFINCLUDE template=&quot;header.cfm&quot;>

And

<CFINCLUDE template=&quot;footer.cfm&quot;>

in onRequestEnd.cfm..

These are default header and footer templates for the site, used best for counters, cf settings, etc..

then index.cfm may contain only the contents it needs, no cfincludes for the header and footers..

Note that if you have a directory like /members/ and no application.cfm in it, then cf files exec'd in that dir will seek up the hierarchy to the drive root for an application.cfm.. so any subdirectories will use your main application and onRquestEnd.cfm files so long as the directory doesn't contain one itself...

Application.cfm does not excute on a cfinclude.. so the header will only effect the browser's call to a file... a cfinclude won't grab the header and footer.

This help?
Tony ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
Hadn't thought about putting them in the application.cfm. I will try that.

Cheers

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top