Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 14th, 2005, 02:06 PM
Authorized User
 
Join Date: Jul 2003
Posts: 52
Thanks: 0
Thanked 0 Times in 0 Posts
Default Write to DataBase HELP!!!

Hi,
I'm trying to learn some javascript by trying to do the functions I need to complete an operation. It fills in a form and submits, then
writes a response. That works fine, but I've tried to add another
sub to write the responses to a database table. I took this routine
from a sample I saw but it is wrong. Can anyone see what I did
wrong in this:
--------------------
Sub InsertReturnData(mySQL)

DIM adoConnection = Server.CreateObject("ADODB.Connection");

    adoConnection.Open("Provider=Microsoft.OLEDB.4.0;D ata Source="(local)\ThePhile;user id=sa;password=xxx;trusted_connection=true"
    mySQL = "INSERT INTO Transactions_TransactionLogJSForm(TransactionType, TotalAmount, Name, CompanyName,";
    mySQL = "ResponseType, ResponseCode, ResponseDescr, AuthCode, TraceNo) VALUES("pg_transaction_type=","pg_total_amount="," ;
    mySQL = ""ecom_billto_postal_name_first=","ecom_billto_pos tal_name_last=","pg_response_type=","pg_response_c ode=","pg_response_description=",";
    mySQL = ""pg_authorization_code=","pg_trace_number=")" ;

    adoConnection.Execute(mySQL);

    adoConnection.Close();
    adoConnection= null;
End Sub
--------------

...thanks for looking.
Reid C.

Reid C.
__________________
Reid C.
 
Old January 15th, 2005, 05:38 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Where does this code run? At the client or at the server?

Right now, t looks like a mix of JavaScript and VBScript and a mix of server side and client side code.....

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Three MC's And One DJ by Beastie Boys (Track 12 from the album: Hello Nasty) What's This?
 
Old January 18th, 2005, 11:35 AM
Authorized User
 
Join Date: Jul 2003
Posts: 52
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Imar,
thanks for your response...and anyone else who sees this
and responds.

this is a program that handles a form, sends it to a
server, and the server sends me a response. Below is the
subroutine that handles the response. It puts it onto
a response page in a simple table form. What I'm trying to
do is ADD another subroutine to take the same response
message and put the fields into a database table as a row.

Here is the response sub and the latest version of my attempt
to add a sub to write the same to the database:
-------------------
'This function writes out the parsed return data in a table format
Sub WriteReturnData(strMsg)
    DIM arrNames(9), arrValues(9)
    arrNames(0)="Merchant Id"
    arrNames(1)="Transaction Type"
    arrNames(2)="Total Amount"
    arrNames(3)="First Name"
    arrNames(4)="Last Name"
    arrNames(5)="Response Type"
    arrNames(6)="Response Code"
    arrNames(7)="Response Description"
    arrNames(8)="Authorization Code"
    arrNames(9)="Trace Number"

    arrValues(0)=ParseString(strMsg,"pg_merchant_id=")
    arrValues(1)=ParseString(strMsg,"pg_transaction_ty pe=")
    arrValues(2)=ParseString(strMsg,"pg_total_amount=" )
    arrValues(3)=ParseString(strMsg,"ecom_billto_posta l_name_first=")
    arrValues(4)=ParseString(strMsg,"ecom_billto_posta l_name_last=")
    arrValues(5)=ParseString(strMsg,"pg_response_type= ")
    arrValues(6)=ParseString(strMsg,"pg_response_code= ")
    arrValues(7)=ParseString(strMsg,"pg_response_descr iption=")
    arrValues(8)=ParseString(strMsg,"pg_authorization_ code=")
    arrValues(9)=ParseString(strMsg,"pg_trace_number=" )

    Response.Write "<center><P><B>Response For Your Check Transaction</B></P>"
    Response.Write "<Table border=0>"
    FOR i=0 TO UBOUND(arrValues)
        IF arrValues(i) > "" THEN
            Response.Write "<tr>"
            Response.Write "<td align=right>" & arrNames(i) & ":&nbsp;</td>"
            Response.Write "<td>" & arrValues(i) & "</td>"
            Response.Write "</tr>"
        END IF
    NEXT
    Response.Write "</Table></center>"

End Sub

' This function 'should' add the same response data above to the datatable "Transactions_TransactionLogJSForm"
Sub InsertReturnData(strMsg)

DIM arrValues(8)
DIM adoConnection = Server.CreateObject("ADODB.Connection");
adoConnection.Open(Data Source="(local)\ThePhile;user id=sa;password=xxx;trusted_connection=true");
    mySQL = "INSERT INTO Transactions_TransactionLogJSForm(TransactionType, TotalAmount, Name, CompanyName,";
    mySQL = "ResponseType, ResponseCode, ResponseDescr, AuthCode, TraceNo) VALUES(arrValues(0)=ParseString(strMsg,"pg_transac tion_type="),";
    mySQL = "arrValues(1)=ParseString(strMsg,"pg_total_amount= "),arrValues(2)=ParseString(strMsg,"ecom_billto_po stal_name_first="),arrValues(3)=ParseString(strMsg ,"ecom_billto_postal_name_last="),";
    mySQL = "arrValues(4)=ParseString(strMsg,"pg_response_type ="),arrValues(5)=ParseString(strMsg,"pg_response_c ode="), arrValues(6)=ParseString(strMsg,"pg_response_descr iption=")";
    mySQL = "arrValues(7)=ParseString(strMsg,"pg_authorization _code="), arrValues(8)=ParseString(strMsg,"pg_trace_number=" ))";

    adoConnection.Execute(mySQL);

    adoConnection.Close();
    adoConnection= null
End Sub
---------------
...once again, the first sub "WriteReturnData" works fine. But I
need some help with the second sub, which I've written from scratch,
as it does not produce the wanted result.
Thx
Reid C.

Reid C.
 
Old January 19th, 2005, 02:58 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

You need to reassign the value of mySql back to mySql when you add something. Take a look at this:

mySQL = "INSERT INTO Transactions_TransactionLogJSForm
        (TransactionType, TotalAmount, Name, CompanyName,";
mySQL = "ResponseType, ResponseCode, ResponseDescr, AuthCode,
    TraceNo) VALUES(arrValues(0)=ParseString (strMsg,"pg_transaction_type="),";

When these two lines are processed, mySql contains only the last line.

So, at the end, when you execute mySql, this is what gets executed:

arrValues(7)=ParseString(strMsg,"pg_authorization_ code="), arrValues(8)=ParseString(strMsg,"pg_trace_number=" ))

Which, of course, doesn't make much sense.

Try something like:

mySql = mySql & "bla bla bla"

Also, you should drop the semi colons at the end of each line. This is VB Script which doesn't use the semi colon.

And more:

mySQL = "arrValues(7)=ParseString(strMsg,"pg_authorization _code="), arrValues(8)=ParseString(strMsg,"pg_trace_number=" ))";

Doesn't make sense, probably.

I think you're trying to get the item with index 7 from an array. However, with thos code you're assigning the text arrValue(7) to the mySql variable.

This should probably something like:

mySql = mySql & arrValues(7) & "whatever"

Finally, if you do post pages like this, can you specify what error you get? "it does not produce the wanted result" isn't really helping us to help you.

I don't want to sound rude, but if I were you I'd get a book about ASP and databases. It looks like you're lacking some fundamental concepts in ASP, VBScript, JavaScript and database access.....

HtH,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Stockholm Syndrome by Muse (Track 5 from the album: Absolution) What's This?





Similar Threads
Thread Thread Starter Forum Replies Last Post
its urgent,write permission to database(mdb). shanwaj ASP.NET 1.0 and 1.1 Basics 2 January 10th, 2008 12:40 PM
Write to a database MMJiggy62 Beginning VB 6 3 August 24th, 2006 12:11 AM
Database Write and Email inquiringminds BOOK: Beginning ASP 3.0 9 September 21st, 2004 06:33 AM
How to read/write Access Database jmmendes Access VBA 0 November 18th, 2003 01:26 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.