Skip to main content
Inspiring
Nov 17, 2022 6:09 PM UTC
Answered

Insert into when a page loads

Hello So I have a page and when it loads I would like to have it insert into a table if a record is matched. In the body I have this:

 

<cfquery name="countlookup" Datasource="#application.datasource#" dbtype="ODBC">
SELECT id as idlx
FROM usercount
</cfquery>
<cfset idl = #countlookup.idlx#>
<cfif #idl# eq '449'>
<cfquery name="countlookup450" Datasource="#application.datasource#" dbtype="ODBC">
INSERT INTO usercount (id)
values (450)
</cfquery></cfif>

Issue I'm seeing is the page loads and doesn't insert anything in the usercount table. What am I messing up? I'm using Coldfusion 2021 woth SQL 2019.

 

Thanks

    This topic is closed to new replies. Start a new post to keep the conversation going.
    EddieLotter
    EddieLotterCorrect answer
    Inspiring
    Nov 17, 2022 8:36 PM UTC

    What you're missing is a where clause in your select query.

    The query is very likely returning multiple rows and the first row does not match '449'.

    3 replies

    EddieLotter
    EddieLotterCorrect answer
    Inspiring
    Nov 17, 2022 8:36 PM UTC

    What you're missing is a where clause in your select query.

    The query is very likely returning multiple rows and the first row does not match '449'.

    Translate
    taunntAuthor
    Inspiring
    Nov 18, 2022 12:28 PM UTC

    Yes you are correct. It's always the small things you miss. after adding where id = '449' it worked.

     

    Thanks

    Translate
    EddieLotter
    Inspiring
    Nov 18, 2022 3:22 PM UTC

    You're welcome. Glad it was an easy fix. 

    Translate