Solved

How to store Function Results into a Database

Posted on 2004-08-13
11
130 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

762 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

18 Experts available now in Live!

Get 1:1 Help Now