Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default Creating a Forum

    Hi there,

    Im creating a forum and which to create a topic entry page, I want to send the
    topic name to the 'topics' table and the message to the 'messages'

    BUT! I will have to get the new topic id from the 'topics' table, which is an
    auto number, so how do i go around it?

    Current code is:




    <cfquery name="inserttopic" datasource="scd">
    INSERT INTO topics (ForumID, TopicName, CreatedBy, DateCreated)
    VALUES ('#form.ForumID#', '#form.TopicName#', '#form.Username#',
    '#DateFormat(Now())#');

    </cfquery>




    <cfquery name="topicID" datasource="scd">
    SELECT TopicID
    FROM topics
    WHERE TopicID = '#inserttopic.TopicID#';
    </cfquery>

    <cfquery name="insertmessage" datasource="scd">
    INSERT INTO messages (TopicID, TopicName, Message, DateCreated)
    VALUES ('#TopicID#', '#form.Username#', '#form.Message#',
    '#DateFormat(Now())#');

    </cfquery>

    Thus I have tried to retrieve the TopicID after the topic has been created,
    but its not working.

    Any help you be great


    <cfquery name="inserttopic" datasource="scd">
    INSERT INTO topics (ForumID, TopicName, CreatedBy, DateCreated)
    VALUES ('#form.ForumID#', '#form.TopicName#', '#form.Username#',
    '#DateFormat(Now())#');

    </cfquery>




    <cfquery name="topicID" datasource="scd">
    SELECT TopicID
    FROM topics
    WHERE TopicID = '#inserttopic.TopicID#';
    </cfquery>

    <cfquery name="insertmessage" datasource="scd">
    INSERT INTO messages (TopicID, TopicName, Message, DateCreated)
    VALUES ('#TopicID#', '#form.Username#', '#form.Message#',
    '#DateFormat(Now())#');

    </cfquery>



    stuart1231 Guest

  2. Similar Questions and Discussions

    1. creating shared folder location hanges when creating a review
      Hi All, I am using Acrobat Pro 8.1.2 for Mac. When I try to create a document for review, I get through all the steps until I get the pop up...
    2. Creating a Message Board (Forum)
      We are creating a message board for a group that will need to login. Can you please give me your recommendations on extensions, etc. that would...
    3. creating a forum using coldfusion and mysql
      Is there an article on a Macromedia tech notes or other sites that shows you step by step in creating a coldfusion and mysql forum such as the one we...
    4. Creating E-mail form, forum, guestbook, etc. (Publisher 2003)
      Hello, 1. I tried to create a Email form using insert HTML Code fragment function although I copy and paste that code correctly and changed an...
    5. New forum
      I have just made myself a site,which will consist of some flashes that i am making, including movies,and some games. The forum...that i am want as...
  3. #2

    Default Re: Creating a Forum

    It depends on what database you're using. In SQL Server or ACCESS you could
    use CFTRANSACTION
    with @@IDENTITY to retrieve the ID of the last topic inserted. CFTRANSACTION
    ensures that you will retrieve the ID of the correct "topic".

    I noticed you're using single quotes around the "forumID". If "forumID" is a
    numeric, you do not need the single quotes. Single quotes are not required when
    inserting into a numeric column. Note, I did not remove the single quotes from
    your code sample.

    You could also use the database date functions to insert the current date,
    instead of CF functions.
    For Access the syntax is...

    --- note, there are no quotes or # signs around the function name
    VALUES (...., now() )

    Or for SQL Server ...

    VALUES (...., getDate() )



    <!--- not tested --->
    <cftransaction (...etc...)>
    <cfquery name="inserttopic" datasource="scd">
    INSERT INTO topics (ForumID, TopicName, CreatedBy, DateCreated)
    VALUES ('#form.ForumID#', '#form.TopicName#', '#form.Username#',
    '#DateFormat(Now())#');
    </cfquery>

    <cfquery name="topicID" datasource="scd">
    SELECT @@IDENTITY AS NewTopicID
    </cfquery>

    <cfquery name="insertmessage" datasource="scd">
    INSERT INTO messages (TopicID, TopicName, Message, DateCreated)
    VALUES ('#topicID.NewTopicID#', '#form.Username#', '#form.Message#',
    '#DateFormat(Now())#');
    </cfquery>

    </cftransaction>

    mxstu Guest

  4. #3

    Default Re: Creating a Forum

    thanks for the reply, i have changed the date formating many thanks.

    I am using an access database.

    I entered your code and it is now saying:

    CFTRANSACTION is unsupported.

    I just have <cftransaction> at the beginning,

    Do u know whats wrong

    (never used cftransaction before)

    stuart1231 Guest

  5. #4

    Default Re: Creating a Forum

    The version you are using may not support this tag ... exactly what version of
    CF are you using ?


    [url]http://livedocs.macromedia.com/coldfusion/7/htmldocs/wwhelp/wwhimpl/common/html/[/url]
    wwhelp.htm?context=ColdFusion_Documentation&file=0 0000346.htm

    mxstu Guest

  6. #5

    Default Re: Creating a Forum

    ahh there is the problem!!!

    I am using Allaire ColdFusion 4.5

    I see my fault!
    stuart1231 Guest

  7. #6

    Default Re: Creating a Forum

    I believe CFTRANSACTION existed even in CF 4, so the version number might not
    be the problem. Which version of CF 4.5 are you using? If you're using the
    "Express" version then I think it is probably not supported. "Express" was
    very limited and did not support a number of tags.

    mxstu Guest

  8. #7

    Default Re: Creating a Forum

    it is express,

    Can i not just download the new coldfusion mx 7 developers as i am just using this pc as a server before the website is launched on a hosted coldfusion server somewhere else
    stuart1231 Guest

  9. #8

    Default Re: Creating a Forum

    Yep!


    On another note, I just took a closer look at your sql statements and you may
    want think about modifying your table structure.

    A) It's not a good idea to store the "TopicName" in two places (Topics and
    Messages) because if the topic name in one table changes, then the records in
    the other table get out-of-synch

    B) If the "CreatedBy" column stores a text username (like "aJohnson"), it
    would be better to use store a numeric user ID instead (for the same reason
    stated above, plus a search on a numeric column is usually faster than
    searching a "text" column).


    A better structure might be ...

    Table (YourUserTableName)
    ====================
    UserID (AutoNumber)
    UserName (text)
    ... other fields...


    Table [Topics]
    ====================
    TopicID (Autonumber)
    ForumID (number)
    TopicName (Text)
    CreatedBy (number)
    DateCreated (date/time) * Default = now()

    Table [Messages]
    ====================
    MessageID (Autonumber)
    TopicID (number)
    Message (Text or Memo)
    CreatedBy (number)
    DateCreated (date/time) * Default = now()




    mxstu Guest

  10. #9

    Default Re: Creating a Forum

    thanks very much, i have taken you comments and changed parts

    Yes that typo caused alot of problems!!!

    Thanks again

    Stu
    stuart1231 Guest

  11. #10

    Default Re: Creating a Forum

    You're welcome. Best of luck!
    mxstu Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139