Forums

This topic is locked

New to asp!

Posted 11 Feb 2007 09:27:38
1
has voted
11 Feb 2007 09:27:38 Gregory Gawaran posted:
First off, hi to everyone, im not new to html, but I am very very new to asp and using dynamic web pages.

Right now, I'm using Dreamweaver 8 and am trying to get my asp page to write simple inserts into the database. However ive run into the following problems,

1) When I run with a recordset I simply get an error saying "Page not found."
2) When I run without the recordset, it displays the test page I made with the form etc. I click submit and I get another page not found error.

Heres the code if you guys could take a look.
This code is with the recordset and insert record coding. I cant really tell what it does, as im still learning everything about dynamic pages. Though, ive been troubled trying to get to the next step, since I cant even get it to write to the database properly.

<pre id=code><font face=courier size=2 id=code>

&lt;%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%&gt;
&lt;!--#include file="Connections/gsideweb.asp" --&gt;
&lt;%
' *** 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 &lt;&gt; "" 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 = ""
%&gt;
&lt;%
' *** Insert Record: set variables

If (CStr(Request("MM_insert") = "membersinfo" Then

MM_editConnection = MM_gsideweb_STRING
MM_editTable = "gsidedb.membersinfo"
MM_editRedirectUrl = "complete.html"
MM_fieldsStr = "first_name|value|last_name|value|address|value|state|value|zipcode|value"
MM_columnsStr = "first_name|',none,''|last_name|',none,''|address|',none,''|state|',none,''|zipcode|none,none,NULL"

' 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 &lt;&gt; "" And Request.QueryString &lt;&gt; "" Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString &lt;&gt; "" Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
End If
End If

End If
%&gt;
&lt;%
' *** Insert Record: construct a sql insert statement and execute it

Dim MM_tableValues
Dim MM_dbValues

If (CStr(Request("MM_insert") &lt;&gt; "" 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 &lt;&gt; "" 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 &lt;&gt; 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 &lt;&gt; "" Then
Response.Redirect(MM_editRedirectUrl)
End If
End If

End If
%&gt;
&lt;%
Dim membersinfo
Dim membersinfo_numRows

Set membersinfo = Server.CreateObject("ADODB.Recordset"
membersinfo.ActiveConnection = MM_gsideweb_STRING
membersinfo.Source = "SELECT * FROM gsidedb.membersinfo"
membersinfo.CursorType = 0
membersinfo.CursorLocation = 2
membersinfo.LockType = 1
membersinfo.Open()

membersinfo_numRows = 0
%&gt;
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="www.w3.org/1999/xhtml"&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /&gt;
&lt;title&gt;Untitled Document&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;form id="membersinfo" name="membersinfo" method="POST" action="&lt;%=MM_editAction%&gt;"&gt;
&lt;input name="first_name" type="text" value="First Name" size="25" maxlength="25" /&gt;
&lt;input name="last_name" type="text" value="Last Name" size="25" maxlength="25" /&gt;
&lt;input name="address" type="text" value="Address" size="25" maxlength="25" /&gt;
&lt;input name="state" type="text" value="State" size="25" maxlength="25" /&gt;
&lt;input name="zipcode" type="text" value="Zipcode" size="25" maxlength="25" /&gt;
&lt;input name="Submit" type="submit" value="submit" /&gt;
&lt;input type="hidden" name="MM_insert" value="membersinfo"&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
&lt;%
membersinfo.Close()
Set membersinfo = Nothing
%&gt;


</font id=code></pre id=code>

Replies

Replied 11 Feb 2007 23:43:28
11 Feb 2007 23:43:28 Charles Knight replied:
Tried to load your code but the top half is commented out.

Do you get any of your form page with the insert record applied?

DW8 | ASP | ACCESS

Reply to this topic