• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Insert into when a page loads

Explorer ,
Nov 17, 2022 Nov 17, 2022

Copy link to clipboard

Copied

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

Views

254

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advocate , Nov 17, 2022 Nov 17, 2022

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'.

Votes

Translate

Translate
Advocate ,
Nov 17, 2022 Nov 17, 2022

Copy link to clipboard

Copied

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'.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 18, 2022 Nov 18, 2022

Copy link to clipboard

Copied

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

 

Thanks

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Nov 18, 2022 Nov 18, 2022

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation