Topic: Entering two values from select


riogrande    -- 07-20-2004 @ 7:14 PM
  Hi all, The value #company# is entered into the database field companygroup. The cfquery getcompany also includes the field companyid. How can I enter this value in the select and in the database field companyid? Thanks a lot for any help

<select name="company" required="Yes" class="profx">
              <option value="0" selected>Please select a company</option>
              <cfoutput query="getcompany">
       companyid         <option value="#company#">#company_name#</option>
              </cfoutput>
            </select>
               
<cfquery datasource='admindb2'>
INSERT INTO znewsmain(title, dateposted, lang, author, authoremail, companygroup, sectionid, doc)
VALUES ('#Trim(FORM.title)#', '#Trim(FORM.postdate)#', '#Trim(FORM.lang)#', '#Trim(FORM.author)#', '#Trim(FORM.authoremail)#',
'#Trim(FORM.company)#', '#Trim(FORM.sectionid)#', '#DocName#')
</cfquery>



falconseye    -- 07-21-2004 @ 10:01 AM
  you know there might be a better and more efficient way to do but what i did was, on the second page where you insert those values i use another query on the top like
<cfquery name="getStuff" datasource="wuteve">
SELECT CompanyName FROM yourtable
WHERE companyid = #form.selectMyCompany#
</cfquery>

then in your insert,
INSERT .....
Values(..., '#getStuff.CompanyName#',....)

once again, there could be a better way to do it...
i hope it helps


riogrande    -- 07-21-2004 @ 3:31 PM
  Hi, thanks for the reply,  I tried the code below and I get this error now, any ideas? Thanks a lot

ODBC Error Code = 37000 (Syntax error or access violation)<P><P> [Microsoft][ODBC Microsoft Access Driver] Syntax error (comma) in query expression 'companygroup = 4,peru'.<P><P><p>The error occurred while processing an element with a general identifier of (CFQUERY), occupying document position (17:1) to (17:47) in the template file news2.cfm

Form.cfm
<select name="sectionid" required="Yes" class="profx">
<option value="0" selected>Select Sector TGS</option>
<cfoutput query="getsectortgs">
<option value="#id#">#section#</option></cfoutput></select>

News2.cfm
<cfinclude template="news3-1.cfm">
<cfquery name="getStuff" datasource='admindb2'>
SELECT Companyid FROM companies
WHERE companygroup = #form.company#
</cfquery>
<cfquery  name="insertnow" datasource='admindb2'>
INSERT INTO znewsmain(title, dateposted, lang, author, authoremail, companygroup, companyid, sectionid, doc)
VALUES ('#Trim(FORM.title)#', '#Trim(FORM.postdate)#', '#Trim(FORM.lang)#', '#Trim(FORM.author)#', '#Trim(FORM.authoremail)#',
'#Trim(FORM.company)#', #getStuff.companyid#, '#Trim(FORM.sectionid)#', '#DocName#')
</cfquery>


CBell    -- 08-10-2004 @ 12:48 PM
  You might try sending one of the fields in a hidden field on the form.  That is what I do when I want to send two fields that refer to one selection box...




EasyCFM.COM ColdFusion Forums : http://archive.easycfm.com/forums
Topic: http://archive.easycfm.com/forums/viewmessages.cfm?Forum=12&Topic=4391