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:
Dell PowerEdge Servers
  #1  
Old June 24th, 2004, 04:57 PM
Jazzjit Jazzjit is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Location: Lombard, IL
Posts: 28 Jazzjit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy **Inserting w/a Twist**

Hey guys, what's going on? I just signed up today so please forgive me if I sound redundant or am missing information. I have a slight problem that hopefully you guys can answer.

Background Info
I have three tables: Material, Units, and UnitMaterials. In my Material table, I have a MaterialId field which is an identity (automatically generated) and in my Unit table, I have a UnitId which is also an identity. The UnitMaterials table is a table where it links these two identities together i.e. putting that material in one or multiple units. Both of these fields must exist in order for this table to work.

Problem
I have a form where the user enters in the material information they want put into the database. That works fine. In the form though, there is no field asking for the MaterialId because it gets automatically generated. Once the user enters in this information, they are prompted with a select box where they can select mulitple units and therefore put that material in those units. My problem is when the user picks these units, the UnitMaterials table is not updated. The material gets added but it does not get placed into a unit.

Here Is Some Of My Code Which Hopefully You Guys Can Find The Problem With

<<<The Form Page For Inserting The Material>>>

<form action="newMSDS_action.cfm" method="post" name="materials" onsubmit='return checkForm();'>
<table border="0" cellpadding="2" cellspacing="2" bgcolor="">
<tr valign="baseline" bgcolor="#FFFFFF">
</tr>
<tr valign="baseline">
<td nowrap align="right"><div align="left" class="style7">* Material:</div></td>
<td colspan="3"><input name="material" type="text" value="" size="50"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right"><div align="left" class="style7 style17">* Manufacturer:</div></td>
<td colspan="3"><input name="mfg" type="text" value="" size="50"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right"><div align="left" class="style7 style17">* Issue Date:</div></td>
<td width="73%"><input name="issueDate" type="text" id="issue date" value="" size="50"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right"><div align="left" class="style7 style17">Shelf Life:</div></td>
<td colspan="3"><input name="shelfLife" type="text" value="" size="50"></td>
</tr>
<INPUT type="hidden" name="materialId" value="<cfoutput>#material.MaterialId#</cfoutput> ">
<td width="27%"><input name="submit" type="submit" value="Insert MSDS"></td>
<td width="73%"><input name="Cancel" type="button" onClick="javascript:document.location='newMSDS.cfm'" value="Cancel"/></td>
</tr>
</table>
</form>

<<<The Action Page For Inserting The Material>>>

<CFQUERY datasource="****" NAME="InsertMaterials">
INSERT INTO dbo.Material (
Material,
Mfg,
IssueDate,
ShelfLife
)
VALUES (
'#Form.Material#',
'#Form.Mfg#',
'#DateFormat(Form.IssueDate,"mm/dd/yyyy")#',
'#Form.ShelfLife#'
)
</CFQUERY>

<cflocation url="newMSDS.cfm?material=#Form.material#">

<<<The Form That Prompts The User With A Select Box Of Units Once The Material Form Is Complete>>>

<cfform action="unitPlacement_action.cfm" method="post" name="unitPlacement">
<table border="0" cellpadding="2" cellspacing="2" bgcolor="">
<tr valign="baseline" bgcolor="#FFFFFF">
</tr>
<tr valign="baseline">
<td nowrap align="right"><div align="left" class="style7"><strong>Units:</strong></div></td>
<td colspan="3"><cfselect name="UnitId"
query="unit"
value="UnitId"
display="Unit"
required="yes"
multiple="yes"
size="4"
>
</cfselect>
</td>
</tr>
<td width="27%"></td>
<td width="27%"><input name="select" type="submit" value="Select Units"></td>
<INPUT type="hidden" name="materialId" value="<cfoutput>#material.MaterialId#</cfoutput>">
</table>
</cfform>

<<<The Action Page For Once The User Selects His Units>>>

<cfif not isDefined("Form.unitPlacement")>
<cflocation url="newMSDS.cfm">
</cfif>

<cfquery name="unitMaterials" datasource="****">
SELECT *
FROM dbo.UnitMaterials
WHERE MaterialId='#Form.materialId#' AND UnitId='#Form.UnitId#'

INSERT INTO dbo.UnitMaterials (
UnitId,
MaterialId
)
VALUES (
'#Form.UnitId#',
'#Form.MaterialId#'
)
</cfquery>
<cflocation url="newMSDS.cfm?unit=#Form.UnitId#">

I know I need a lot of code help so please, ANY HELP WOULD BE GREATLY APPRECIATED!!! Thanks so much guys!

~ Jazz

Reply With Quote
  #2  
Old June 24th, 2004, 08:06 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
Can you run these queries form the command line (or your SQL IDE)?

Are you getting an error? If so, what is it?

It looks like your query "unitMaterials" has two problems to me. The first is that if the user picks more than one item from the select box, you'll need to loop over that query and do an insert for each item they picked. And second, where are you getting the "material.MaterialId" and/or "unitID" variables?
__________________
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 24th, 2004, 09:03 PM
Jazzjit Jazzjit is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Location: Lombard, IL
Posts: 28 Jazzjit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
On my new material form page, I have created two queries as follows:

<cfquery name="unit" datasource="****">
SELECT *
FROM dbo.Unit
ORDER BY Unit.Unit
</cfquery>

<cfquery name="material" datasource="****">
SELECT *
FROM dbo.Material
</cfquery>

Using these queries and the form, is where I get my "unitID" and "material.MaterialId" variables. This is the way I thought I can get my MaterialId that was just created and pass it to the action form to add it to the units via unitId. Im sure it is probably wrong or a better way to do it...Im just so lost! You mentioned using a loop over the query...I know you mean to use a <cfloop> but am not sure how to implement it. I also dont know what you mean when you say "Can you run these queries form the command line (or your SQL IDE)?" When the units are selected for the material and clicked to submit...all that happens is that it goes back to the add a material page...so it basically does not do anything. I hope this information helps and that we can work to find the solution! Thanks for the prompt response.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > **Inserting w/a Twist**


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 1 hosted by Hostway