Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_databases thread: ASP / Database


Message #1 by "jim" <jasmin_shah@h...> on Mon, 11 Nov 2002 15:02:27
I need to create a database which collects the customer information and 
placed into access database when they make a purchase on the website. I 
have got there basic info in but how do i make it so when they go buy an 
item that the price gets pulled form the database, caluculates the 
quantity, and gets displayed. here is the thing that i did in frontpage.

<%
' FP_ASP ASP Automatically generated by a Frontpage Component. Do not Edit.

On Error Resume Next
Session("FP_OldCodePage") = Session.CodePage
Session("FP_OldLCID") = Session.LCID
Session.CodePage = 1252
Session.LCID = 1033
Err.Clear

strErrorUrl = ""

If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
If Request.Form("VTI-GROUP") = "0" Then
	Err.Clear

	Set fp_conn =  Server.CreateObject("ADODB.Connection")
	FP_DumpError strErrorUrl, "Cannot create connection"

	Set fp_rs = Server.CreateObject("ADODB.Recordset")
	FP_DumpError strErrorUrl, "Cannot create record set"

	fp_conn.Open Application("form3_ConnectionString")
	FP_DumpError strErrorUrl, "Cannot open database"

	fp_rs.Open "Results", fp_conn, 1, 3, 2 ' adOpenKeySet, 
adLockOptimistic, adCmdTable
	FP_DumpError strErrorUrl, "Cannot open record set"

	fp_rs.AddNew
	FP_DumpError strErrorUrl, "Cannot add new record set to the 
database"
	Dim arFormFields0(9)
	Dim arFormDBFields0(9)
	Dim arFormValues0(9)

	arFormFields0(0) = "PostalCode"
	arFormDBFields0(0) = "PostalCode"
	arFormValues0(0) = Request("PostalCode")
	arFormFields0(1) = "StateORProvince"
	arFormDBFields0(1) = "StateORProvince"
	arFormValues0(1) = Request("StateORProvince")
	arFormFields0(2) = "Address_2"
	arFormDBFields0(2) = "Address_2"
	arFormValues0(2) = Request("Address_2")
	arFormFields0(3) = "FAX"
	arFormDBFields0(3) = "FAX"
	arFormValues0(3) = Request("FAX")
	arFormFields0(4) = "City"
	arFormDBFields0(4) = "City"
	arFormValues0(4) = Request("City")
	arFormFields0(5) = "Phone"
	arFormDBFields0(5) = "Phone"
	arFormValues0(5) = Request("Phone")
	arFormFields0(6) = "Name"
	arFormDBFields0(6) = "Name"
	arFormValues0(6) = Request("Name")
	arFormFields0(7) = "Country"
	arFormDBFields0(7) = "Country"
	arFormValues0(7) = Request("Country")
	arFormFields0(8) = "Address"
	arFormDBFields0(8) = "Address"
	arFormValues0(8) = Request("Address")

	FP_SaveFormFields fp_rs, arFormFields0, arFormDBFields0

	If Request.ServerVariables("REMOTE_HOST") <> "" Then
		FP_SaveFieldToDB fp_rs, Request.ServerVariables
("REMOTE_HOST"), "Remote_computer_name"
	End If
	If Request.ServerVariables("HTTP_USER_AGENT") <> "" Then
		FP_SaveFieldToDB fp_rs, Request.ServerVariables
("HTTP_USER_AGENT"), "Browser_type"
	End If
	FP_SaveFieldToDB fp_rs, Now, "Timestamp"
	If Request.ServerVariables("REMOTE_USER") <> "" Then
		FP_SaveFieldToDB fp_rs, Request.ServerVariables
("REMOTE_USER"), "User_name"
	End If

	fp_rs.Update
	FP_DumpError strErrorUrl, "Cannot update the database"

	fp_rs.Close
	fp_conn.Close

	FP_FormConfirmation "text/html; charset=windows-1252",_
						"Form Confirmation",_
						"Thank you for submitting 
the following information:",_
						"form.asp",_
						"Return to the form."

End If
End If

Session.CodePage = Session("FP_OldCodePage")
Session.LCID = Session("FP_OldLCID")

%>
<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Name</title>
</head>


<TITLE></TITLE>


</HEAD>

<BODY BGCOLOR="" BACKGROUND="bg.gif" TEXT="#000000" LINK="#0000FF" 
VLINK="#0000FF">



<SCRIPT LANGUAGE="JavaScript">      
function MakeTen(expr,decimal){
	var str="" + Math.round(eval(expr) * Math.pow(10,decimal))
	while (str.length <= decimal){
	   str = "0" + str
	}
	var decpoint = str.length - decimal
	return str.substring(0,decpoint) + "." + str.substring
(decpoint,str.length);
}

function MakeTwo(expr){
	return "$" + MakeTen(expr,2)
}

        function cartMe() {
                index = document.cookie.indexOf("MyCart");
                countbegin = (document.cookie.indexOf("=", index) + 1);
                countend = document.cookie.indexOf(";", index);
                if (countend == -1) {
                        countend = document.cookie.length;
                }
               fulllist = document.cookie.substring(countbegin, countend);
		totprice = 0;
		document.writeln('<form action="http://66.166.171.29 /" 
ENCTYPE="application/x-www-form-urlencoded" method=POST>');
		document.writeln('<B><FONT SIZE=6><FONT COLOR=2e8da9>Order 
Form</FONT></FONT></B><TABLE BORDER=1 CELLSPACING=2 CELLPADDING=2 
BGCOLOR=adcfdc>');


                itemlist = 0;
                for (var i = 0; i <= fulllist.length; i++) {
                        if (fulllist.substring(i,i+1) == '[') {
                                itemstart = i+1;
                        } else if (fulllist.substring(i,i+1) == ']') {
                                itemend = i;
                                thequantity = fulllist.substring
(itemstart, itemend);
                                itemtotal = 0;
                                itemtotal = (eval(theprice*thequantity));
                                temptotal = itemtotal * 100;
                                totprice = totprice + itemtotal;
                                itemlist=itemlist+1;
document.writeln('<tr><td align=middle>'+thequantity+'</td><td 
align=left>'+theitem+'</td><td align=right>'+theoption+'</td><td 
align=right>$'+theprice+'</td><td align=right>'+MakeTwo(itemtotal)
+'</td></tr>');
 				document.writeln('<INPUT TYPE="hidden" 
NAME="Qty" VALUE=" '+thequantity+' " 
SIZE="40">');                               
				 document.writeln('<INPUT TYPE="hidden" 
NAME="Product" VALUE=" '+theitem+ '" SIZE="40">');           
				 document.writeln('<INPUT TYPE="hidden" 
NAME="Option" VALUE=" '+theoption+ '" SIZE="40">');                    
                                document.writeln('<INPUT TYPE="hidden" 
NAME="Price" VALUE=" '+theprice+ '" SIZE="40">');
                                document.writeln('<INPUT TYPE="hidden" 
NAME="SubTotal" VALUE=" '+MakeTwo(itemtotal)+'0 " SIZE="40">');
 


                                
                        } else if (fulllist.substring(i,i+1) == ',') {
                                theitem = fulllist.substring(itemstart, i);
                                itemstart = i+1;
                        } else if (fulllist.substring(i,i+1) == '^') {
                                theprice = fulllist.substring(itemstart, 
i);
                                itemstart = i+1;
                        } else if (fulllist.substring(i,i+1) == '~') {
                                theoption = fulllist.substring(itemstart, 
i);
                                itemstart = i+1;
                        }
                }

                document.writeln('<tr><td align=right 
colspan=4><b>Total</b></td><td align=right>'+MakeTwo(totprice)
+'</td></tr>');
                document.writeln('<INPUT TYPE="hidden" NAME="Total: " 
VALUE=" '+MakeTwo(totprice)+'" SIZE="40">');
                document.writeln('</TABLE>');

        }</SCRIPT>

<body>

<form method="POST" action="--WEBBOT-SELF--" onsubmit="return 
FrontPage_Form1_Validator(this)" language="JavaScript" 
name="FrontPage_Form1">
  <!--webbot bot="SaveDatabase" suggestedext="asp" u-asp-include-
url="_fpclass/fpdbform.inc" s-dataconnection="form3" s-
recordsource="Results" u-database-url="fpdb/form3.mdb" s-builtin-
fields="REMOTE_HOST HTTP_USER_AGENT Timestamp REMOTE_USER" s-builtin-
dbfields="Remote_computer_name Browser_type Timestamp User_name" s-form-
fields="PostalCode StateORProvince Address_2 FAX City Phone Name Country 
Address" s-form-dbfields="PostalCode StateORProvince Address_2 FAX City 
Phone Name Country Address" startspan --><input TYPE="hidden" NAME="VTI-
GROUP" VALUE="0"><!--#include file="_fpclass/fpdbform.inc"--><!--webbot 
bot="SaveDatabase" endspan i-checksum="40548" --><p align="center">
  Name:
  <input type="text" name="Name" size="20"></p>
  <p align="center">
  Address:
  <input type="text" name="Address" size="20"></p>
  <p align="center">
  Address 2:
  <input type="text" name="Address_2" size="20"></p>
  <p align="center">
  City:
  <input type="text" name="City" size="20"></p>
  <p align="center">
  State/Province: <input type="text" name="StateORProvince" size="20"></p>
  <p align="center">
  Postal Code:
  <!--webbot bot="Validation" s-data-type="Number" s-number-
separators="x." --><input type="text" name="PostalCode" size="20"></p>
  <p align="center">
  Country:
  <input type="text" name="Country" size="20"></p>
  <p align="center">
  Phone Number:&nbsp;&nbsp; <input type="text" name="Phone" size="20"></p>
  <p align="center">
  Fax Number:
  <input type="text" name="FAX" size="20"></p>
  <p>&nbsp;</p>
  <p align="center"><input type="submit" value="Submit" name="B1"><input 
type="reset" value="Reset" name="B2"></p>
</form>
<form method="POST" action="--WEBBOT-SELF--">
  <!--webbot bot="SaveResults" u-file="_private/form_results.csv" s-
format="TEXT/CSV" s-label-fields="TRUE" startspan --><input TYPE="hidden" 
NAME="VTI-GROUP" VALUE="1"><!--webbot bot="SaveResults" endspan i-
checksum="43406" --><p>&nbsp;</p>
</form>

</body>

</html>

  Return to Index