Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsOtherProgramming Help

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 ASP Free Forums Sponsor:
  #1  
Old May 26th, 2004, 01:25 PM
chabuhi chabuhi is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 89 chabuhi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 7 h 55 m 54 sec
Reputation Power: 5
Newbie ? - Form data inserts to db constantly

I'm trying to create a form page that writes data to an sql table only when the user clicks the "save" button. I actually have it working, however it works ALWAYS! In other words, if you fill in the fields and click "save" it inserts that data into the database like it should ... BUT, it also creates empty recordsets whenever you first bring up the page, refresh it, or return to it from another page.

I'm gathering, from articles I've read, that I probably need to control this through some sort of IF...THEN statement. I've tried to do this, but I just can't seem to make it work. (The code below doesn't contain my failed IF...THEN attempt):

'<%
'Set cnnDB = Server.CreateObject("ADODB.Connection")
'cnnDB.Open application("dbConn")
'%>
'
'<FORM METHOD="POST" ACTION="thispage.asp">...
'FORM omitted for the sake of brevity
'...</FORM>
'
'<%
'sql="INSERT INTO mytable (col1, col2, col3) VALUES ('" &_
'field1 & "','" & field2 & "','" & field3 & "')"'
'
'cnnDB.execute(sql)
'
'cnnDB.Close
'Set cnnDB = Nothing
'%>

I appreciate any suggestions - Thanks!

Reply With Quote
  #2  
Old May 26th, 2004, 01:36 PM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
ASP Free God 14th Plane (11500 - 11999 posts)
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,760 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 5 h 18 m 17 sec
Reputation Power: 443
Just a simple example.
Code:
If(Request.Form("FieldName") = "") Then
   The field is empty, don't insert
   insert = false
Else
   insert = true
End If

If(insert = true) Then
   Insert into the database
End If

Reply With Quote
  #3  
Old May 26th, 2004, 04:01 PM
chabuhi chabuhi is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 89 chabuhi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 7 h 55 m 54 sec
Reputation Power: 5
I hadn't even considered making the fields the conditional ... I had been focusing on making the "Save" button the deciding factor, but your method works just fine (maybe I can figure out how to wrap it around the button instead of a field).

Thanks!

Reply With Quote
  #4  
Old May 26th, 2004, 05:55 PM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
ASP Free God 14th Plane (11500 - 11999 posts)
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,760 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 5 h 18 m 17 sec
Reputation Power: 443
You might consider validating the form on the client using javascript.

Reply With Quote
Reply

Viewing: ASP Free ForumsOtherProgramming Help > Newbie ? - Form data inserts to db constantly


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


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





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