Inserting several rows ad ones into a database
I'm building a shopping-cart like feature with Dreamweaver MX 2004, an access database and ASP & VbScript.
I'm now at the point where I need to add several rows to the same table in the database. Each time the amount of rows that need to be added tot the database varies from 1 row to however many orders a customer places. I'm cappable to make this function for one single row. But not for orders with several rows.
So can someone please tell me how to accomplise this. I've added the codeof my page at the bottom of this post. So I need to know what code to add and where to accomplish this.
Thanks in advance.
Zoe-Alyssa
Quote: <<A href="mailto:%@LANGUAGE="VBSCRIPT">%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="../Connections/rainbow.asp" -->
<%
' *** 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 = ""
%>
<%
' *** Update Record: set variables
If (CStr(Request("MM_update")) = "frm_test42" And CStr(Request("MM_recordId")) <> "") Then
MM_editConnection = MM_rainbow_STRING
MM_editTable = "mandje"
MM_editColumn = "mandje_id"
MM_recordId = "" + Request.Form("MM_recordId") + ""
MM_editRedirectUrl = "confirm2.asp"
MM_fieldsStr = "hf_mandjeid|value|hf_klantvoornaam|value|hf_klanta chternaam|value|hf_geslacht|value|hf_telefoon|valu e|hf_bedrijfsnaam|value|hf_kvk|value|hf_btw|value| hf_badres|value|hf_bpostcode|value|hf_bwpl|value|h f_fadres|value|hf_fpostcode|value|hf_fwpl|value|hf _zelfde|value|hf_bestelt|value"
MM_columnsStr = "mandje_id|none,none,NULL|voornaam|',none,''|achter naam|',none,''|geslacht|',none,''|telefoon|',none, ''|bedrijfsnaam|',none,''|kvknummer|',none,''|btwn ummer|',none,''|badres|',none,''|bpostcode|',none, ''|bwpl|',none,''|fadres|',none,''|fpostcode|',non e,''|fwpl|',none,''|zelfde|none,none,NULL|bestelt| none,Yes,No"
' 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
%>
<%
' *** Update Record: construct a sql update statement and execute it
If (CStr(Request("MM_update")) <> "" And CStr(Request("MM_recordId")) <> "") Then
' create the sql update statement
MM_editQuery = "update " & MM_editTable & " set "
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_editQuery = MM_editQuery & ","
End If
MM_editQuery = MM_editQuery & MM_columns(MM_i) & " = " & MM_formVal
Next
MM_editQuery = MM_editQuery & " where " & MM_editColumn & " = " & MM_recordId
If (Not MM_abortEdit) Then
' execute the update
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
%>
<%
Dim rs_mandjeinhoudinkt__MMColParam
rs_mandjeinhoudinkt__MMColParam = "1"
If (Session("MM_Username") <> "") Then
rs_mandjeinhoudinkt__MMColParam = Session("MM_Username")
End If
%>
<%
Dim rs_mandjeinhoudinkt
Dim rs_mandjeinhoudinkt_numRows
Set rs_mandjeinhoudinkt = Server.CreateObject("ADODB.Recordset")
rs_mandjeinhoudinkt.ActiveConnection = MM_rainbow_STRING
rs_mandjeinhoudinkt.Source = "SELECT * FROM mandje WHERE email = '" + Replace(rs_mandjeinhoudinkt__MMColParam, "'", "''") + "' and bestelt = false"
rs_mandjeinhoudinkt.CursorType = 0
rs_mandjeinhoudinkt.CursorLocation = 2
rs_mandjeinhoudinkt.LockType = 1
rs_mandjeinhoudinkt.Open()
rs_mandjeinhoudinkt_numRows = 0
%>
<%
Dim rs_klantgegevens__MMColParam
rs_klantgegevens__MMColParam = "1"
If (Session("MM_Username") <> "") Then
rs_klantgegevens__MMColParam = Session("MM_Username")
End If
%>
<%
Dim rs_klantgegevens
Dim rs_klantgegevens_numRows
Set rs_klantgegevens = Server.CreateObject("ADODB.Recordset")
rs_klantgegevens.ActiveConnection = MM_rainbow_STRING
rs_klantgegevens.Source = "SELECT email, geslacht, voornaam, achternaam, bedrijfsnaam, kvknummer, btwnummer, badres, bpostcode, bwoonplaats, telefoonnummer, fadres, fpostcode, fwoonplaats, zelfde FROM klant WHERE email = '" + Replace(rs_klantgegevens__MMColParam, "'", "''") + "'"
rs_klantgegevens.CursorType = 0
rs_klantgegevens.CursorLocation = 2
rs_klantgegevens.LockType = 1
rs_klantgegevens.Open()
rs_klantgegevens_numRows = 0
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index
Repeat1__numRows = -1
Repeat1__index = 0
rs_mandjeinhoudinkt_numRows = rs_mandjeinhoudinkt_numRows + Repeat1__numRows
%>
<!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>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<form ACTION="<%=MM_editAction%>" METHOD="POST" name="frm_test42" id="frm_test42">
<table width="100%" border="1">
<tr>
<td><%=(rs_klantgegevens.Fields.Item("voornaam").Value)%></td>
<td rowspan="4">
<%
While ((Repeat1__numRows <> 0) AND (NOT rs_mandjeinhoudinkt.EOF))
%>
<table width="100%" border="1">
<tr>
<td> <%=(rs_mandjeinhoudinkt.Fields.Item("omschrijving").Value)%>
<input name="hf_mandjeid" type="hidden" id="hf_mandjeid" value="<%=(rs_mandjeinhoudinkt.Fields.Item("mandje_id").Value)%>" />
<input name="hf_klantvoornaam" type="hidden" id="hf_klantvoornaam" value="<%=(rs_klantgegevens.Fields.Item("voornaam").Value)%>" />
<input name="hf_klantachternaam" type="hidden" id="hf_klantachternaam" value="<%=(rs_klantgegevens.Fields.Item("achternaam").Value)%>" />
<input name="hf_geslacht" type="hidden" id="hf_geslacht" value="<%=(rs_klantgegevens.Fields.Item("geslacht").Value)%>" />
<input name="hf_telefoon" type="hidden" id="hf_telefoon" value="<%=(rs_klantgegevens.Fields.Item("telefoonnummer").Value)%>" />
</td>
</tr>
<tr>
<td><%=(rs_mandjeinhoudinkt.Fields.Item("wat").Value)%>
<input name="hf_bedrijfsnaam" type="hidden" id="hf_bedrijfsnaam2" value="<%=(rs_klantgegevens.Fields.Item("bedrijfsnaam").Value)%>" />
<input name="hf_kvk" type="hidden" id="hf_kvk2" value="<%=(rs_klantgegevens.Fields.Item("kvknummer").Value)%>" />
<input name="hf_btw" type="hidden" id="hf_btw2" value="<%=(rs_klantgegevens.Fields.Item("btwnummer").Value)%>" /></td>
</tr>
<tr>
<td><%=(rs_mandjeinhoudinkt.Fields.Item("aantal").Value)%>
<input name="hf_badres" type="hidden" id="hf_badres2" value="<%=(rs_klantgegevens.Fields.Item("badres").Value)%>" />
<input name="hf_bpostcode" type="hidden" id="hf_bpostcode2" value="<%=(rs_klantgegevens.Fields.Item("bpostcode").Value)%>" />
<input name="hf_bwpl" type="hidden" id="hf_bwpl3" value="<%=(rs_klantgegevens.Fields.Item("bwoonplaats").Value)%>" />
<input name="hf_fadres" type="hidden" id="hf_fadres2" value="<%=(rs_klantgegevens.Fields.Item("fadres").Value)%>" />
<input name="hf_fpostcode" type="hidden" id="hf_fpostcode2" value="<%=(rs_klantgegevens.Fields.Item("fpostcode").Value)%>" />
<input name="hf_fwpl" type="hidden" id="hf_fwpl2" value="<%=(rs_klantgegevens.Fields.Item("fwoonplaats").Value)%>" /></td>
</tr>
<tr>
<td><%=(rs_mandjeinhoudinkt.Fields.Item("prijsincl").Value)%>
<input name="hf_zelfde" type="hidden" id="hf_zelfde" value="<%=(rs_klantgegevens.Fields.Item("zelfde").Value)%>" />
<input name="hf_bestelt" type="hidden" id="hf_bestelt" value="-1" />
</td>
</tr>
</table>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
rs_mandjeinhoudinkt.MoveNext()
Wend
%>
<table width="100%" border="1">
<tr>
<td><input type="submit" name="Submit" value="Submit" /></td>
</tr>
</table></td>
</tr>
<tr>
<td><%=(rs_klantgegevens.Fields.Item("achternaam").Value)%></td>
</tr>
<tr>
<td><%=(rs_klantgegevens.Fields.Item("badres").Value)%></td>
</tr>
<tr>
<td><%=(rs_klantgegevens.Fields.Item("bwoonplaats").Value)%></td>
</tr>
</table>
<table width="100%" border="1">
<tr>
<td> </td>
<td> </td>
</tr>
</table>
<input type="hidden" name="MM_update" value="frm_test42">
<input type="hidden" name="MM_recordId" value="<%= rs_mandjeinhoudinkt.Fields.Item("mandje_id").Value %>">
</form>
</body>
</html>
<%
rs_mandjeinhoudinkt.Close()
Set rs_mandjeinhoudinkt = Nothing
%>
<%
rs_klantgegevens.Close()
Set rs_klantgegevens = Nothing
%> |
|