Solved

How to store Function Results into a Database

Posted on 2004-08-13
11
131 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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:adilkhan
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

For those who don't know, Adobe Dreamweaver is a popular commercial web editor that enables you to design, build and manage complex websites. The editor is a WYSIWYG (What You See Is What You Get) web editor, which means that you can create your web…
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 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 …
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

867 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now