?
Solved

How to store Function Results into a Database

Posted on 2004-08-13
11
Medium Priority
?
138 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying 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 500 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

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

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

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…
This article is very specific and is only intended to help if you are installing Dreamweaver 8 in a Windows 7 environment with Office 2007 installed.   I'm not sure why Microsoft tends to release OS' that should not be released but they do.  Windows…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…

839 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