Forum Moderators: open

Message Too Old, No Replies

Inserting form fields into database (ASP used)

         

neo_neo

1:00 am on Nov 20, 2010 (gmt 0)

10+ Year Member



hello new member here
I'm trying insert fields from a web page form into an access database. within dreamweaver, i inserted server behaviors from and from that tab in dreamweaver, by clicking insert record for each field on the form. i am inserting multiple fields into multiple database tables. the problem is that that each field inserts into another database record so for example the person's name would be created as one record and their email address as a new record.
how do i fix this, should i post the ASP code? or can you all help with the steps to rectify it in Dreamweaver?
thanks in advance

Demaestro

2:05 am on Nov 20, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Start by posting the ASP that you have.

neo_neo

3:05 am on Nov 20, 2010 (gmt 0)

10+ Year Member



<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="Connections/RequestBooking.asp" -->
<%
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_insert")) = "Bookingfrm") Then
If (Not MM_abortEdit) Then
' execute the insert
Dim MM_editCmd1

Set MM_editCmd = Server.CreateObject ("ADODB.Command")
MM_editCmd.ActiveConnection = MM_RequestBooking_STRING
MM_editCmd.CommandText = "INSERT INTO Customer (CustomerName) VALUES (?)"
MM_editCmd.Prepared = true
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param1", 202, 1, 255, Request.Form("customername")) ' adVarWChar
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close
End If
End If
%>
<%
If (CStr(Request("MM_insert")) = "Bookingfrm") Then
If (Not MM_abortEdit) Then
' execute the insert
Dim MM_editCmd2

Set MM_editCmd = Server.CreateObject ("ADODB.Command")
MM_editCmd.ActiveConnection = MM_RequestBooking_STRING
MM_editCmd.CommandText = "INSERT INTO Customer (CustomerEmail) VALUES (?)"
MM_editCmd.Prepared = true
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param1", 202, 1, 255, Request.Form("email")) ' adVarWChar
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close
End If
End If
%>
<%
If (CStr(Request("MM_insert")) = "Bookingfrm") Then
If (Not MM_abortEdit) Then
' execute the insert
Dim MM_editCmd3

Set MM_editCmd = Server.CreateObject ("ADODB.Command")
MM_editCmd.ActiveConnection = MM_RequestBooking_STRING
MM_editCmd.CommandText = "INSERT INTO Customer (CustomerTelephone) VALUES (?)"
MM_editCmd.Prepared = true
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param1", 202, 1, 255, Request.Form("telephone")) ' adVarWChar
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close
End If
End If
%>
<%
If (CStr(Request("MM_insert")) = "Bookingfrm") Then
If (Not MM_abortEdit) Then
' execute the insert
Dim MM_editCmd4

Set MM_editCmd = Server.CreateObject ("ADODB.Command")
MM_editCmd.ActiveConnection = MM_RequestBooking_STRING
MM_editCmd.CommandText = "INSERT INTO Event (VenueAddress) VALUES (?)"
MM_editCmd.Prepared = true
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param1", 202, 1, 255, Request.Form("venueaddress")) ' adVarWChar
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close
End If
End If
%>
<%
If (CStr(Request("MM_insert")) = "Bookingfrm") Then
If (Not MM_abortEdit) Then
' execute the insert
Dim MM_editCmd5

Set MM_editCmd = Server.CreateObject ("ADODB.Command")
MM_editCmd.ActiveConnection = MM_RequestBooking_STRING
MM_editCmd.CommandText = "INSERT INTO Event (StartTime) VALUES (?)"
MM_editCmd.Prepared = true
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param1", 135, 1, -1, MM_IIF(Request.Form("starttime"), Request.Form("starttime"), null)) ' adDBTimeStamp
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close
End If
End If
%>
<%
If (CStr(Request("MM_insert")) = "Bookingfrm") Then
If (Not MM_abortEdit) Then
' execute the insert
Dim MM_editCmd6

Set MM_editCmd = Server.CreateObject ("ADODB.Command")
MM_editCmd.ActiveConnection = MM_RequestBooking_STRING
MM_editCmd.CommandText = "INSERT INTO Booking (OnlineBooking) VALUES (?)"
MM_editCmd.Prepared = true
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param1", 5, 1, -1, MM_IIF(Request.Form("onlinebooking"), 1, 0)) ' adDouble
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close
End If
End If
%>
<%
Dim Recordset1
Dim Recordset1_cmd
Dim Recordset1_numRows

Set Recordset1_cmd = Server.CreateObject ("ADODB.Command")
Recordset1_cmd.ActiveConnection = MM_RequestBooking_STRING
Recordset1_cmd.CommandText = "SELECT PackageName FROM Package"
Recordset1_cmd.Prepared = true

Set Recordset1 = Recordset1_cmd.Execute
Recordset1_numRows = 0
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Make Booking</title>


This is the ASP code generated by dreamweaver. I dont know much about coding ASP, but it looks like for each field, there is a new ADODB connection being opened and closed, so i was thinking to manually edit the code so that it would retrieve all fields in one connection. the following is what i've edited to try to achieve this


MM_editCmd.CommandText = "INSERT INTO Customer (CustomerEmail) VALUES (?)"

Request.Form("email")) ' adVarWChar

MM_editCmd.CommandText = "INSERT INTO Customer (CustomerTelephone) VALUES (?)"

MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param1", 202, 1, 255, Request.Form("telephone")) ' adVarWChar

neo_neo

11:43 pm on Nov 22, 2010 (gmt 0)

10+ Year Member



ok i dont need the solution again...