ColdFusion Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreColdFusion Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old June 29th, 2004, 10:36 AM
mkm mkm is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 104 mkm User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 h 51 m 53 sec
Reputation Power: 4
newbie - problem with insert

Hello,

I have a form with two tables. The first table is a bunch of drop down fields that the user selects and sends the info to an action page that inserts the data into a table.

The second table has four input boxes, each with a hidden variable. The info is sent to a different action page where there are a bunch of if statements that insert the data into different tables depending on the hidden variable.

The first table/form/insert works great but the second one doesn't work at all.

Here is the code for the second table:
Code:
<cfform action="addData.cfm" method="POST">
<table align="center" width="400">
  <tr>
    <td colspan="2"><font color="#0000CC">You can add data to the
	      dropdown lists by typing in the textboxes below. NOTE: Submitting new
	      data to the list will refresh the form.</font>
    </td>
  </tr>
  <tr>
    <td>Refuge Abbreviation:</td>
  	<td>
		<input type="text" name="add_reflist" value="" size="40">
		<INPUT TYPE="hidden" NAME="submittype" VALUE="reflist">
	</td>
  </tr>
  <tr>
  	<td>Requestor:</td>
    <td>
		<input type="text" name="add_requestor" value="" size="40">
		<INPUT TYPE="hidden" NAME="submittype" VALUE="requestor">
	</td>
  </tr>
  <tr>
  	<td>Requestor Office:</td>
    <td>
		<input type="text" name="add_reqoffice" value="" size="40">
		<INPUT TYPE="hidden" NAME="submittype" VALUE="reqoffice">
	</td>
  </tr>
  <tr>
    <td>Project Type:</td>
    <td>
		<input type="text" name="add_projtype" value="" size="40">
		<INPUT TYPE="hidden" NAME="submittype" VALUE="projtype">
	</td>
  </tr>
  <tr>
  	<td>Map Type:</td>
    <td>
		<input type="text" name="add_maptype" value="" size="40">
		<INPUT TYPE="hidden" NAME="submittype" VALUE="maptype">
	</td>
  </tr>
  	<td align="center" colspan="2"><input name="submit" type="submit" value="Add to List"></td>
</table>
</cfform>


and here is the code for the action page:

Code:
<CFIF #form.submittype# IS "reflist">
<cfquery datasource="PLOG">
  INSERT INTO data_admin.Status_Log (Literal) VALUES (
  <cfif IsDefined("FORM.add_reflist") AND #FORM.add_reflist# NEQ "">
    '#FORM.add_reflist#'
      <cfelse>
      NULL
  </cfif>
  )
  </cfquery>
</CFIF>

<CFIF #form.submittype# IS "requestor">
<cfquery datasource="PLOG">
  INSERT INTO data_admin.Requestor (Requestor) VALUES (
  <cfif IsDefined("FORM.add_requestor") AND #FORM.add_requestor# NEQ "">
    '#FORM.add_requestor#'
      <cfelse>
      NULL
  </cfif>
  )
  </cfquery>
</CFIF>

<CFIF #form.submittype# IS "reqoffice">
<cfquery datasource="PLOG">
  INSERT INTO data_admin.Requestor_Office (Requestor_Office) VALUES (
  <cfif IsDefined("FORM.add_reqoffice") AND #FORM.add_reqoffice# NEQ "">
    '#FORM.add_reqoffice#'
      <cfelse>
      NULL
  </cfif>
  )
  </cfquery>
</CFIF>

<CFIF #form.submittype# IS "projtype">
<cfquery datasource="PLOG">
  INSERT INTO data_admin.Project_Type (Project_Type) VALUES (
  <cfif IsDefined("FORM.add_projtype") AND #FORM.add_projtype# NEQ "">
    '#FORM.add_projtype#'
      <cfelse>
      NULL
  </cfif>
  )
  </cfquery>
</CFIF>

<CFIF #form.submittype# IS "maptype">
<cfquery datasource="PLOG">
  INSERT INTO data_admin.Map_Type (Map_Type) VALUES (
  <cfif IsDefined("FORM.add_maptype") AND #FORM.add_maptype# NEQ "">
    '#FORM.add_maptype#'
      <cfelse>
      NULL
  </cfif>
  )
  </cfquery>
</CFIF>

<body>
<cfoutput>
<p><b><div align="center"> The following data has been added: </div>
</b></p>
<table align="center">
  <tr>
    <td>Refuge Literal:</td>
	<td>#FORM.add_reflist#</td>
  	</tr>
  <tr>
  	<td>Requestor:</td>
	<td>#FORM.add_requestor#</td>
    </tr>
  <tr>
  	<td>Requestor Office:</td>
	<td>#FORM.add_reqoffice#</td>
    </tr>
  <tr>
    <td>Project Type:</td>
	<td>#FORM.add_projtype#</td>
    </tr>
  <tr>
  	<td>Map Type:</td>
	<td>#FORM.add_maptype#</td>
    </tr></table>
</cfoutput>
<div align="center"><a href="main.cfm?page_name=addJob">Return to Project Insert</a> | <a href="main.cfm">Return to Main</a></div></p>
</body>


Can anyone see what I am doing wrong? The code for the action page for the first table is virtually the same but all the data is inserted into one table instead of using if statements to determine which table to inset into.

Thanks for any help!!
melissa

Reply With Quote
  #2  
Old June 29th, 2004, 11:03 AM
kiteless kiteless is offline
Moderator
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,488 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 18 h 10 m 11 sec
Reputation Power: 42
Are you getting an error message? Can you distill this down to just a test situation using one or two fields to narrow down where the problem is? Honestly that's just too much code for me to sift through in a reasonable time.
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian.
How to Post a Question in the Forums

Reply With Quote
  #3  
Old June 29th, 2004, 11:34 AM
mkm mkm is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 104 mkm User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 h 51 m 53 sec
Reputation Power: 4
Sorry about that.

No, no error message, just no new data inserted into the tables. I know the info is being sent from the form page to the action page because the info I type in to the input boxes are displayed, as in the following does work:
Code:
<p><b><div align="center"> The following data has been added: 
    <td>Refuge Literal:</td>
	<td>#FORM.add_reflist#</td>


but when I return to the first form nothing new appears in the dropdown boxes and when I look at the tables themselves no new data appears.

Is there a way to check if the INSERT statement is working, like through some sort of trace?

Thanks for your time!
melissa

Reply With Quote
  #4  
Old June 29th, 2004, 12:43 PM
kiteless kiteless is offline
Moderator
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,488 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 18 h 10 m 11 sec
Reputation Power: 42
If you turn on debugging you can set it to show all the SQL code that executed during the request. I'd start by making sure that your tables are set to take null for all the columns. Also, you can copy the SQL code from the debugging output and attempt to run it within your database's IDE to track down the problem.

Actually, taking another look at your code I think I might see the problem. You're using a hidden form field called "submittype", and you're setting it to multiple values within the same form. If you do this and you post the form, CF will treat "form.submittype" as a comma-delimited list of ALL of these values. In other words, I don't think CF is ever getting just one value, it's getting a list of ALL the values of submittype every time you submit the form. You can confirm this by outputting "form.submittype" on the action page to see what it's getting. You'll either need to make each option a separate form, or use some other way to determine what the submittype was (possibly checking the text boxes for which one has text in it, etc.).

Reply With Quote
  #5  
Old June 29th, 2004, 01:01 PM
mkm mkm is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 104 mkm User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 h 51 m 53 sec
Reputation Power: 4
Hey you are right I AM getting a comma delimted list of all them! The weird thing is this setup worked for another situation, slightly similar.

In that case I had two different forms submitting to the same action page. One form was to add a job and another form (separate cfm page) to edit a job. Both had a hidden variable (submittype = insert for one and submittype = update for the other). There is a similar if statement setup that checks the value of the submittype and then either does and INSERT or an UPDATE to the same table. When I output the submittype variable in that situation it outputs only one value (the correct one thankfully!).

So I thought I could use a similar setup in this new situation but maybe not? Do I have to have a separate action page for each one then?

Thanks again!
melissa

Reply With Quote
  #6  
Old June 29th, 2004, 01:05 PM
kiteless kiteless is offline
Moderator
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,488 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 18 h 10 m 11 sec
Reputation Power: 42
No you don't need separate action pages for each one, though that would probably be much easier to maintain than having all the insert statements in one file. The more programming you do the more you'll appreciate encapsulation and cohesiveness: the idea that any one file should have only 1 task, and should do that 1 task in the most efficient way. When a file (or object or method or whatever) starts taking on multiple responsibilities, complexity and maintenance headaches are not far behind...

Once you understand CFML in general, I'd recommend looking at a framework like Fusebox or Mach-II to help organize your code.

Regards,

Brian

Reply With Quote
  #7  
Old June 30th, 2004, 10:16 AM
mkm mkm is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 104 mkm User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 h 51 m 53 sec
Reputation Power: 4
Quote:
Originally Posted by kiteless
You'll either need to make each option a separate form, or use some other way to determine what the submittype was (possibly checking the text boxes for which one has text in it, etc.).


Hi all,

I am still banging my head on this problem and can't figure out a solution to make it work. I would like to avoid having one action page for every insert. Is it possible to create one form that checks to see which text box has text in it, and if it has text do an insert into it's corresponding table? There are four text boxes for four tables. Couldn't I use a series of cfif statements to check for a value in the box?

Thanks for any help!
melissa

Reply With Quote
  #8  
Old June 30th, 2004, 10:24 AM
kiteless kiteless is offline
Moderator
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,488 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 18 h 10 m 11 sec
Reputation Power: 42
Sure, just use <cfif len( trim( form.someField ) )> which will be true if the field has anything in it.

Reply With Quote
  #9  
Old June 30th, 2004, 10:49 AM
mkm mkm is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 104 mkm User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 h 51 m 53 sec
Reputation Power: 4
Great! But then how can I make my form page work with the four separate INSERT statements? Do I just use the logic of "if the textbox from the form has text in it then insert that into whichever table" ? And so forget having the hidden form variable that has the same name but different values depending on the box and just use the input box names straight up?

Anyone else confused yet? lol . . .

thanks,
melissa

**EDIT** Nevermind! I got it! I don't know why I was trying to make it so hard when it was so simple! Thanks Brian, you are awesome!!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > newbie - problem with insert


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway