Solved

How to store Function Results into a Database

Posted on 2004-08-13
11
133 Views
Last Modified: 2010-04-25
I want to store  “Total Score()”  that is printed on the screen with the “document.writeln…”  into a database.

How to I store the data generated by the “getTotalScore()” into a database??


Code:

function getTotalScore()  {
    var scoreResult = 0;

    }
    return scoreResult;


The line below prints the value stored in getTotalScore() on the screen:
     

  document.writeln("<TD ALIGN='CENTER'><font size='2'><B>" + getTotalScore() + "</B></TD>")
0
Comment
Question by:Nmagsaysay
11 Comments
 
LVL 8

Expert Comment

by:alexhogan
ID: 11800893
Just pass the result of the function to the query.

varReturnfromFunction = getTotalScore()

INSERT INTO myTable (myField)
VALUES (varReturnfromFunction)
0
 
LVL 14

Expert Comment

by:Esopo
ID: 11801308
What server will you be using? (ISS, Apache, etc)
Scripting language? (PHP, ASP, ASP.NET, etc)

Check this links:

- For PHP - MySql
  https://www.ucl.ac.uk/is/mysql/dreamweaver/
  http://www.webmasterworld.com/forum48/1552.htm

- Access DB
  http://www.informit.com/articles/article.asp?p=101755&redir=1


Best regards,

Esopo.
0
 

Author Comment

by:Nmagsaysay
ID: 11803075
I'm using IIS server.

I can't figure out where to insert:

varReturnfromFunction = getTotalScore()

INSERT INTO myTable (myField)
VALUES (varReturnfromFunction)


Where do I insert it - in head, body, before head, between <%  %>?

Do I add this text into the page containing the function or can it be added to a different page after the function?

Do I create a Recordset and Insert from the Server Behavior?
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

Author Comment

by:Nmagsaysay
ID: 11804238
ASP language is used.
0
 
LVL 8

Expert Comment

by:alexhogan
ID: 11804425
You will need to create a recordset first.

Then you can create a server behavior to make insert.  That is the easiest way.

However, if you were to code this by hand you would;

Put the code in or above the head tags,  although code can be placed anywhere on the page
And
You would put the code between the code tags.  For asp they are the <%  %> tags.

0
 

Author Comment

by:Nmagsaysay
ID: 11804719
I tried both the recordset and the insert.

Where do I place the:

??         varReturnfromFunction = getTotalScore()

??         INSERT INTO myTable (myField)                
??         VALUES (varReturnfromFunction)

And, do I place this on the same page as the function or can I place the form to insert data on a different page.



0
 
LVL 8

Accepted Solution

by:
alexhogan earned 250 total points
ID: 11805121
Unless you include# the page with the function on the second page you will need to put it on the same page as the function.

Place the insert code after the function call.
0
 

Author Comment

by:Nmagsaysay
ID: 11806793
Created Recordset and Insert from Behavior.  Added the suggested commands but received an error message:


•      Error Type:
Microsoft VBScript compilation (0x800A0401)
Expected end of statement
/cats/summary1.asp, line 334, column 12
INSERT INTO [Cats Table] (Score)
-----------^

Here are the codes:

<%
Dim Recordset1
Dim Recordset1_numRows

Set Recordset1 = Server.CreateObject("ADODB.Recordset")
Recordset1.ActiveConnection = MM_conCats_STRING
Recordset1.Source = "SELECT UserTime, UseScore FROM [Cats Table]"
Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 1
Recordset1.Open()

Recordset1_numRows = 0
%>




function getTotalScore() {
    .
    .
    .
    return Result;
}

.
.
.

//-->
</SCRIPT>

</HEAD>



<BODY bgcolor="#FFFFFF" onLoad="sendResults()">

<%
varReturnfromFunction = getTotalScore()

INSERT INTO [Cats Table] (Score)
VALUES (varReturnfromFunction)

 %>

.
.
.

        document.writeln("<TD ALIGN='CENTER'><font size='2'><B>" + getTotalScore() + "</B></TD>")

.
.
.

</script>
    <form name="form1" method="POST" action="<%=MM_editAction%>">
      <input type="text" name="textfield">
      <input type="text" name="textfield">
      <input type="submit" name="Submit" value="Submit">
      <input type="hidden" name="MM_insert" value="form1">
</form>
     
</BODY>
</HTML>

0
 
LVL 23

Expert Comment

by:Saqib Khan
ID: 11807193
<%
Score_ = "<Script>getTotalScore()</Script>"
varReturnfromFunction = Score_
INSERT INTO [Cats Table] (Score)
VALUES (varReturnfromFunction)

 %>
0
 

Author Comment

by:Nmagsaysay
ID: 11814623
I changed the <% as suggested, received the same error message:

•     Error Type:
Microsoft VBScript compilation (0x800A0401)
Expected end of statement
/cats/summary1.asp, line 338, column 12
INSERT INTO [Cats Table] (Score)
0
 

Author Comment

by:Nmagsaysay
ID: 11822263
No Solutions, still cannot store the data generated by the “getTotalScore()” into a database.
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I still run into .cgi files every now and then. In some instances, I actually prefer the simplicity of a .cgi script to other options. Since I use DreamWeaver extensively, what I needed was a way to open .cgi scripts in Dreamweaver. And I wanted to …
Adobe Dreamweaver CS5 is a WYSIWYG web page editor that has advanced HTML, CSS, and Javascript rendering functionality and is probably the most well-known HTML editor available. Much of Dreamweaver's appeal centers around the Design View interfac…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question