Solved

How to store Function Results into a Database

Posted on 2004-08-13
11
132 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
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

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 …
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 Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

770 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