|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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! |
|
#2
|
||||
|
||||
|
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
|
|
#3
|
|||
|
|||
|
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! |
|
#4
|
||||
|
||||
|
You might consider validating the form on the client using javascript.
|
![]() |
| Viewing: ASP Free Forums > Other > Programming Help > Newbie ? - Form data inserts to db constantly |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|