Welcome to Dream.In.Code
Click Here
Getting Help is Easy!

Join 118,484 Programmers for FREE! Ask your question and get quick answers from experts. There are 961 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



database updates

 
Reply to this topicStart new topic

database updates, need a loop?

lezlieao
post 17 Oct, 2007 - 12:19 PM
Post #1


New D.I.C Head

*
Joined: 26 Sep, 2007
Posts: 7


My Contributions


Okay, so I am creating an admin page that lists different sets of the database for possible updates. I know i am going to need some kind of loop (i think) to get this to go through each of many fields and update, but I don't know where to begin!

This is what i have for the form (it is repeated twice for the different options)

CODE

<cfform action="admin2.cfm" method="post">

            
            <table width="80%">
            <tr>
                <td><strong>Status</strong></td>
                <td><strong>First Name</strong></td>
                <td><strong>Last Name</strong></td>
                <td><strong>Email</strong></td>
                <td><strong>Position</strong></td>
                <td><strong>Telephone</strong></td>
                <td><strong>Ext</strong>.</td>
                <td><strong>Fax </strong></td>
                <td><strong>Login </strong></td>
                <td><strong>Password </strong></td>
                <td><strong>ASP Wet Chem </strong></td>
                <td><strong>ASP Soybean </strong></td>
                <td><strong>ASP Soybean Meal </strong></td>
                <td><strong>Study Collaborator NIR </strong></td>
                <td><strong>Study Collaborator AAM </strong></td>
            </tr>
            <cfif appearance is "waiting">
            <cfoutput query="waiting">
            <tr>
                <td><input <cfif (#status# EQ 1)>checked="checked"</cfif> type="checkbox" name="status" size="2" value="#status#"></td>
                <td><input type="text" name="first_name" size="8" value="#first_name#"></td>
                <td><input type="text" name="last_name" size="8" value="#last_name#"></td>
                <td><input type="text" name="email" size="15" value="#email#"></td>
                <td><input type="text" name="title" size="8" value="#title#"></td>
                <td><input type="text" name="phone" size="8" value="#phone#"></td>
                <td><input type="text" name="ext" size="2" value="#ext#"></td>
                <td><input type="text" name="fax" size="8" value="#fax#"></td>
                <td><input type="text" name="uid" size="8" value="#uid#"></td>
                <td><input type="text" name="passwd" size="6" value="#passwd#"></td>
                <td><input <cfif (#asp_wc# EQ 1)>checked="checked"</cfif> type="checkbox" name="wc" size="2" value="#asp_wc#"></td>
                <td><input <cfif (#asp_sb# EQ 1)>checked="checked"</cfif> type="checkbox" name="sb" size="2" value="#asp_sb#"></td>
                <td><input <cfif (#asp_sbm# EQ 1)>checked="checked"</cfif> type="checkbox" name="sbm" size="2" value="#asp_sbm#"></td>
                <td><input <cfif (#sc_nir# EQ 1)>checked="checked"</cfif> type="checkbox" name="scnir" size="2" value="#sc_nir#">
                <td><input<cfif (#sc_aam# EQ 1)>checked= "checked"</cfif> type="checkbox" name="scaam" size="2" value="#sc_aam#">
            </tr>
            </cfoutput>
            <cfelseif appearance is "new">
            <cfoutput query="new">
            <tr>


and this is my processing page:

CODE

<title>Admin2</title>
<cfif IsDefined("Form.insertcontacts") is True>
  
   <cfquery name="edit" datasource="sqt_access">
       UPDATE contacts
    SET
    first_name = '#form.first_name#',
    last_name = '#form.last_name#',
    email = '#form.email#',
    title = '#form.title#',
    phone = '#form.phone#',
    ext = '#form.ext#',
    fax = '#form.fax#',
    uid = '#form.uid#',
    asp_sb = '#form.sb#',
    asp_sbm = '#form.sbm',
    asp_wc = '#form.wc#',
    sc_nir = '#form.nir#',
    sc_aam = '#form.aam#',
    edited = '1',
    status = '#form.status#'
    
    WHERE passwd = '#(form.passwd)#'

   </cfquery>
   </cfif>
   <cflocation url = "admin.cfm">



Please help! Thanks
User is offlineProfile CardPM

Go to the top of the page


dswens
post 23 Oct, 2007 - 06:03 PM
Post #2


New D.I.C Head

*
Joined: 16 Oct, 2007
Posts: 34


My Contributions


Are you generating any errors with the current setup or does this work as it is and you are just trying to make your code more intelligent?
User is offlineProfile CardPM

Go to the top of the page

lezlieao
post 24 Oct, 2007 - 12:18 PM
Post #3


New D.I.C Head

*
Joined: 26 Sep, 2007
Posts: 7


My Contributions


QUOTE(dswens @ 23 Oct, 2007 - 06:03 PM) *

Are you generating any errors with the current setup or does this work as it is and you are just trying to make your code more intelligent?



It doesn't generate any errors as is, it just doesn't actually update the database.
User is offlineProfile CardPM

Go to the top of the page

skyhawk133
post 24 Oct, 2007 - 12:21 PM
Post #4


Head DIC Head

Group Icon
Joined: 17 Mar, 2001
Posts: 14,605



Thanked 39 times

Dream Kudos: 1650

Expert In: Web Development

My Contributions


Can you see the entire query being executed in the debugger? What happens when you copy/paste that query in to SQL directly?
User is offlineProfile CardPM

Go to the top of the page

lezlieao
post 24 Oct, 2007 - 01:48 PM
Post #5


New D.I.C Head

*
Joined: 26 Sep, 2007
Posts: 7


My Contributions


QUOTE(skyhawk133 @ 24 Oct, 2007 - 12:21 PM) *

Can you see the entire query being executed in the debugger? What happens when you copy/paste that query in to SQL directly?


I'm not sure I understand, but I believe it would start sending errors about each line of the form, if they were not filled in.
User is offlineProfile CardPM

Go to the top of the page

skyhawk133
post 24 Oct, 2007 - 01:55 PM
Post #6


Head DIC Head

Group Icon
Joined: 17 Mar, 2001
Posts: 14,605



Thanked 39 times

Dream Kudos: 1650

Expert In: Web Development

My Contributions


QUOTE(lezlieao @ 24 Oct, 2007 - 02:48 PM) *

QUOTE(skyhawk133 @ 24 Oct, 2007 - 12:21 PM) *

Can you see the entire query being executed in the debugger? What happens when you copy/paste that query in to SQL directly?


I'm not sure I understand, but I believe it would start sending errors about each line of the form, if they were not filled in.


You should be able to turn on the debugger for your IP address in the CF Admin. This will show you all the queries that were run on the page and actually show you the full query that was passed to the database. if you don't see the query in the debugger, chances are your code never made it to it and it's a logic problem... if you see the query, copy and paste it in to SQL Manager and run it... see if any rows were effected, if not, then you need to re-work your query... probably a where clause being too restrictive or incorrectly done.
User is offlineProfile CardPM

Go to the top of the page

MizAthyKat
post 29 Oct, 2007 - 07:47 AM
Post #7


New D.I.C Head

*
Joined: 29 Oct, 2007
Posts: 1


My Contributions


With regard to your query not updating the database, it is likely that you are searching for a value that does not exist, or you need to reconsider the WHERE clause in your update query.
You might want to try using:
WHERE trim(passwd) = '#(form.passwd)#'

With regard to turning on/off your debug info and query results, I put this in the top of my page:
<cfset request.showquerydetails = "Y">

While ALSO having this in the application.cfm page:
<CFsetting showdebugoutput = "Yes">

User is offlineProfile CardPM

Go to the top of the page

supersssweety
post 29 Oct, 2007 - 07:56 AM
Post #8


D.I.C Regular

Group Icon
Joined: 16 Mar, 2007
Posts: 303



Dream Kudos: 125
My Contributions


are all of those entries filled out...I mean...will any of them be null?
User is offlineProfile CardPM

Go to the top of the page

lezlieao
post 29 Oct, 2007 - 11:37 AM
Post #9


New D.I.C Head

*
Joined: 26 Sep, 2007
Posts: 7


My Contributions


QUOTE(supersssweety @ 29 Oct, 2007 - 07:56 AM) *

are all of those entries filled out...I mean...will any of them be null?


Some checkboxes and even possibly some text fields could be left null. Yes...I know this is causing me some problems, but I didn't think it would affect the update yet??
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 10/11/08 06:17AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month