Forums
This topic is locked
DW8 Insert Record Not Working But No Error Message
Posted 03 Dec 2006 03:13:00
1
has voted
03 Dec 2006 03:13:00 Sterling Snyder posted:
Hello all. I'm a pretty compitent ASP programmer but I've found that using Dreamweaver's built-in functionality for inserting records or pulling recordsets can be a huge time saver. Anyway, today I've created a simple form and made my DB connection without incident and even set up an insert record behavior with a redirect page to go to after the form is submitted. The problem is that when you submit the form, nothing happens. The page just reloads itself with the post form data but it does nothing with it. No records are inserted into the database. Nothing happens. I checked the IIS logs and everything looks completely normal. No error messages. Here's my code: Please give me a hand to tell my what in the world might be happening. I've got beer for the person who can help out. <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle> Thanks!' *** Edit Operations: declare variables
Dim MM_editAction
Dim MM_abortEdit
Dim MM_editQuery
Dim MM_editCmd
Dim MM_editConnection
Dim MM_editTable
Dim MM_editRedirectUrl
Dim MM_editColumn
Dim MM_recordId
Dim MM_fieldsStr
Dim MM_columnsStr
Dim MM_fields
Dim MM_columns
Dim MM_typeArray
Dim MM_formVal
Dim MM_delim
Dim MM_altVal
Dim MM_emptyVal
Dim MM_i
MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME")
If (Request.QueryString <> "" Then
MM_editAction = MM_editAction & "?" & Server.HTMLEncode(Request.QueryString)
End If
' boolean to abort record edit
MM_abortEdit = false
' query string to execute
MM_editQuery = ""
%>
<%
' *** Insert Record: set variables
If (CStr(Request("MM_insert") = "SeekerForm" Then
MM_editConnection = MM_SOSIGroup_DSN_Conn_STRING
MM_editTable = "JobSeekers"
MM_editRedirectUrl = "InputJobSeekersConfirm.asp"
MM_fieldsStr = "01_First_Name|value|01_Last_Name|value"
MM_columnsStr = "db_First_Name|',none,''|db_Last_Name|',none,''"
' create the MM_fields and MM_columns arrays
MM_fields = Split(MM_fieldsStr, "|"
MM_columns = Split(MM_columnsStr, "|"
' set the form values
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_fields(MM_i+1) = CStr(Request.Form(MM_fields(MM_i)))
Next
' append the query string to the redirect URL
If (MM_editRedirectUrl <> "" And Request.QueryString <> "" Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "" Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
End If
End If
End If
%>
<%
' *** Insert Record: construct a sql insert statement and execute it
Dim MM_tableValues
Dim MM_dbValues
If (CStr(Request("MM_insert") <> "" Then
' create the sql insert statement
MM_tableValues = ""
MM_dbValues = ""
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_formVal = MM_fields(MM_i+1)
MM_typeArray = Split(MM_columns(MM_i+1),","
MM_delim = MM_typeArray(0)
If (MM_delim = "none" Then MM_delim = ""
MM_altVal = MM_typeArray(1)
If (MM_altVal = "none" Then MM_altVal = ""
MM_emptyVal = MM_typeArray(2)
If (MM_emptyVal = "none" Then MM_emptyVal = ""
If (MM_formVal = "" Then
MM_formVal = MM_emptyVal
Else
If (MM_altVal <> "" Then
MM_formVal = MM_altVal
ElseIf (MM_delim = "'" Then ' escape quotes
MM_formVal = "'" & Replace(MM_formVal,"'","''" & "'"
Else
MM_formVal = MM_delim + MM_formVal + MM_delim
End If
End If
If (MM_i <> LBound(MM_fields)) Then
MM_tableValues = MM_tableValues & ","
MM_dbValues = MM_dbValues & ","
End If
MM_tableValues = MM_tableValues & MM_columns(MM_i)
MM_dbValues = MM_dbValues & MM_formVal
Next
MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & " values (" & MM_dbValues & ""
If (Not MM_abortEdit) Then
' execute the insert
Set MM_editCmd = Server.CreateObject("ADODB.Command"
MM_editCmd.ActiveConnection = MM_editConnection
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close
If (MM_editRedirectUrl <> "" Then
Response.Redirect(MM_editRedirectUrl)
End If
End If
End If
And the form looks like:
<form METHOD="POST" action="<%=MM_editAction%>" enctype="multipart/form-data" name="SeekerForm" id="SeekerForm">
<table width="100%" border="0" cellspacing="0" cellpadding="3">
<tr>
<td colspan="3">Please fill out this brief form to submit a new job seeker profile. </td>
</tr>
<tr>
<td width="5%" valign="middle"><div align="right"><img src="../images/Bullet.gif" alt=">" width="12" height="10" /></div></td>
<td width="21%"><p>First Name:</p></td>
<td width="74%"><input name="01_First_Name" type="text" id="01_First_Name" size="40" /></td>
</tr>
<tr>
<td width="5%" valign="middle"><div align="right"><img src="../images/Bullet.gif" alt=">" width="12" height="10" /></div></td>
<td width="21%"><p>Last Name:</p></td>
<td width="74%"><input name="01_Last_Name" type="text" id="01_Last_Name" size="40" /></td>
</tr>
<tr>
<td colspan="3"><div align="center">
<input type="submit" name="Submit" value="Submit" />
</div></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="SeekerForm">
</form>
Thanks again!!
Replies
Replied 07 Dec 2006 09:14:03
07 Dec 2006 09:14:03 Dave Clarke replied:
I was having this problem and pulling my hair out, see www.dmxzone.com/forum/topic.asp?topic_id=36787
turns out i had somehow set <b>enctype="multipart/form-data"</b> in my form and that only works if you have a file field in your form.
I see from your code you have no file field but you have the <b>enctype="multipart/form-data"</b>, so this could be the same problem.
There should be no enctype set for a form with no file fields.
DW8.02|ASP|VBScript|IIS5.1|Access|WinXPPro & WinXPHome.
www.reunite.co.uk
Edited by - Davecl on 07 Dec 2006 09:30:33
turns out i had somehow set <b>enctype="multipart/form-data"</b> in my form and that only works if you have a file field in your form.
I see from your code you have no file field but you have the <b>enctype="multipart/form-data"</b>, so this could be the same problem.
There should be no enctype set for a form with no file fields.
DW8.02|ASP|VBScript|IIS5.1|Access|WinXPPro & WinXPHome.
www.reunite.co.uk
Edited by - Davecl on 07 Dec 2006 09:30:33
Replied 08 Dec 2006 23:40:01
08 Dec 2006 23:40:01 Sterling Snyder replied:
Dave, I'm not sure I'll be able to ship beer to the UK but I plan on visiting in 2007 and I'd love to buy you a beer. (or five) THANK YOU! That was precisely the problem. It works just fine now. Thank you so much! - Sterling
Replied 09 Dec 2006 08:35:57
09 Dec 2006 08:35:57 Dave Clarke replied:
No problem Sterling, I don't drink anyway <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>
Glad you got it working.
DW8.02|ASP|VBScript|IIS5.1|Access|WinXPPro & WinXPHome.
www.reunite.co.uk
Glad you got it working.
DW8.02|ASP|VBScript|IIS5.1|Access|WinXPPro & WinXPHome.
www.reunite.co.uk
Replied 20 Sep 2007 15:21:38
20 Sep 2007 15:21:38 Doug Mouncey replied:
I am having the exact same problem but I have set no enctype set as I am not uploading any files.
The form works fine when being used with localhost but as soon as it is on the production server the form just reloads and doesn't update the database or redirect.
Code looks like this:
Dim MM_editAction
MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME")
If (Request.QueryString <> "" Then
MM_editAction = MM_editAction & "?" & Server.HTMLEncode(Request.QueryString)
End If
' boolean to abort record edit
Dim MM_abortEdit
MM_abortEdit = false
' IIf implementation
Function MM_IIf(condition, ifTrue, ifFalse)
If condition = "" Then
MM_IIf = ifFalse
Else
MM_IIf = ifTrue
End If
End Function
If (CStr(Request("MM_update") = "form1" Then
If (Not MM_abortEdit) Then
' execute the update
Dim MM_editCmd
Set MM_editCmd = Server.CreateObject ("ADODB.Command"
MM_editCmd.ActiveConnection = MM_ashton_STRING
MM_editCmd.CommandText = "UPDATE tbl_links SET fld_textlink = ?, fld_url = ?, fld_text_desc = ? WHERE id = ?"
MM_editCmd.Prepared = true
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param1", 202, 1, 50, Request.Form("fld_textlink") ' adVarWChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param2", 202, 1, 50, Request.Form("fld_url") ' adVarWChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param3", 202, 1, 50, Request.Form("fld_text_desc") ' adVarWChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param4", 5, 1, -1, MM_IIF(Request.Form("MM_recordId", Request.Form("MM_recordId", null)) ' adDouble
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close
' append the query string to the redirect URL
Dim MM_editRedirectUrl
MM_editRedirectUrl = "links.asp"
If (Request.QueryString <> "" Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0) Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
End If
End If
Response.Redirect(MM_editRedirectUrl)
End If
End If
Dim rsLinks__MMColParam
rsLinks__MMColParam = "1"
If (Request.QueryString("id" <> "" Then
rsLinks__MMColParam = Request.QueryString("id"
End If
Dim rsLinks
Dim rsLinks_cmd
Dim rsLinks_numRows
Set rsLinks_cmd = Server.CreateObject ("ADODB.Command"
rsLinks_cmd.ActiveConnection = MM_ashton_STRING
rsLinks_cmd.CommandText = "SELECT * FROM tbl_links WHERE id = ?"
rsLinks_cmd.Prepared = true
rsLinks_cmd.Parameters.Append rsLinks_cmd.CreateParameter("param1", 5, 1, -1, rsLinks__MMColParam) ' adDouble
Set rsLinks = rsLinks_cmd.Execute
rsLinks_numRows = 0
Form has usual MM_editAction as action for the form.
There are three text fields:
fld_textlink, fld_url and fld_text_desc
Plus hidden fields:
MM_update with value form1 (which is the correct name of the form)
MM_recordId which takes Id from recordset
Works absolutely brilliantly on my local server just when placed on production.
I have checked permission sof database and I can use another script in same location to delete entries from the database.
Does anybody have any ideas?
The form works fine when being used with localhost but as soon as it is on the production server the form just reloads and doesn't update the database or redirect.
Code looks like this:
Dim MM_editAction
MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME")
If (Request.QueryString <> "" Then
MM_editAction = MM_editAction & "?" & Server.HTMLEncode(Request.QueryString)
End If
' boolean to abort record edit
Dim MM_abortEdit
MM_abortEdit = false
' IIf implementation
Function MM_IIf(condition, ifTrue, ifFalse)
If condition = "" Then
MM_IIf = ifFalse
Else
MM_IIf = ifTrue
End If
End Function
If (CStr(Request("MM_update") = "form1" Then
If (Not MM_abortEdit) Then
' execute the update
Dim MM_editCmd
Set MM_editCmd = Server.CreateObject ("ADODB.Command"
MM_editCmd.ActiveConnection = MM_ashton_STRING
MM_editCmd.CommandText = "UPDATE tbl_links SET fld_textlink = ?, fld_url = ?, fld_text_desc = ? WHERE id = ?"
MM_editCmd.Prepared = true
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param1", 202, 1, 50, Request.Form("fld_textlink") ' adVarWChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param2", 202, 1, 50, Request.Form("fld_url") ' adVarWChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param3", 202, 1, 50, Request.Form("fld_text_desc") ' adVarWChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param4", 5, 1, -1, MM_IIF(Request.Form("MM_recordId", Request.Form("MM_recordId", null)) ' adDouble
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close
' append the query string to the redirect URL
Dim MM_editRedirectUrl
MM_editRedirectUrl = "links.asp"
If (Request.QueryString <> "" Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0) Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
End If
End If
Response.Redirect(MM_editRedirectUrl)
End If
End If
Dim rsLinks__MMColParam
rsLinks__MMColParam = "1"
If (Request.QueryString("id" <> "" Then
rsLinks__MMColParam = Request.QueryString("id"
End If
Dim rsLinks
Dim rsLinks_cmd
Dim rsLinks_numRows
Set rsLinks_cmd = Server.CreateObject ("ADODB.Command"
rsLinks_cmd.ActiveConnection = MM_ashton_STRING
rsLinks_cmd.CommandText = "SELECT * FROM tbl_links WHERE id = ?"
rsLinks_cmd.Prepared = true
rsLinks_cmd.Parameters.Append rsLinks_cmd.CreateParameter("param1", 5, 1, -1, rsLinks__MMColParam) ' adDouble
Set rsLinks = rsLinks_cmd.Execute
rsLinks_numRows = 0
Form has usual MM_editAction as action for the form.
There are three text fields:
fld_textlink, fld_url and fld_text_desc
Plus hidden fields:
MM_update with value form1 (which is the correct name of the form)
MM_recordId which takes Id from recordset
Works absolutely brilliantly on my local server just when placed on production.
I have checked permission sof database and I can use another script in same location to delete entries from the database.
Does anybody have any ideas?