Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing Variables to a Database

Status
Not open for further replies.

GeeBee2

Technical User
Aug 29, 2005
12
US
I am using action script to pass quiz data to an ASP application that will save the data to a database. The problem that I am experiencing is that when the action script calls the ASP app it inserts a blank record than it will insert my data...."I am pulling my hair out"

I have included the Actionscript and the asp file that it is calling...any suggestions anyone.

*****************************************************************************

ACTION SCRIPT

userScore=(numOfQuestionsAnsweredCorrectly*100)/
(numOfQuestionsAnsweredIncorrectly+numOfQuestionsAnsweredCorrectly)



myDate = new Date();
dateTextField = (mydate.getMonth() + "/" + myDate.getDate() + "/" + mydate.getFullYear());



quiztitle = "FACTS 101"

myData.final=userScore
myData.date = dateTextField
myData.quiz = quiztitle
myData.studentname = username
myData.sendAndLoad(" myData, "POST")

myData = new LoadVars()
myData.onLoad = function(){
if(this.writing=="Ok") {
gotoAndStop(65)
status.text = "Submited data was saved"
} else status.text = "Error in saving submitted data"
trace(this.writing)
trace(dateTextField)
}
stop();


###################################################################

SAVEFLASH.ASP SCRIPT


<%@Language="VBScript"%>
<%
'Option Explicit
Dim oRS, oConn ' Recordset and connection objects

Set oConn = Server.CreateObject("ADODB.Connection")
oConn.ConnectionString = "Driver={Microsoft Access Driver (*.mdb)};" & _
"DBQ=" & Server.MapPath("students.mdb")
oConn.Open

Set oRS = Server.CreateObject("ADODB.Recordset")
oRS.Open "SELECT * FROM scores", oConn, 2, 3

oRS.AddNew
oRS("Quiz")=Request("quiz")
oRS("Score")=Request("final")
oRS("quizdate")=Request("date")
oRS("user")=Request("studentname")
oRS.Update
Response.Write "writing=Ok&"


' Clean up and say goodbye.
oRS.Close
Set oRS = Nothing
oConn.Close
Set oConn = Nothing

%>
 
Try this in your actionscript

Code:
function sendInfo() {
	userScore = (numOfQuestionsAnsweredCorrectly*100)/(numOfQuestionsAnsweredIncorrectly+numOfQuestionsAnsweredCorrectly);
	myDate = new Date();
	dateTextField = (mydate.getMonth()+"/"+myDate.getDate()+"/"+mydate.getFullYear());
	quiztitle = "FACTS 101";
	
	//Create the LoadVars object to send the variables
	myDataSend = new LoadVars();
	myDataSend.final = userScore;
	myDataSend.date = dateTextField;
	myDataSend.quiz = quizTitle;
	myDataSend.studentname = username;
	
	// create a response LoadVars object
	aspResponse = new LoadVars();
	aspResponse.onLoad = function() {
		if (this.writing == "Ok") {
			gotoAndStop(65);
			//rename your text box instance name to a non-reserved name
			statusText.text = "Submitted data was saved";
		} else {
			statusText.text = "Error in saving submitted data";
		}
	};
	myDataSend.sendAndLoad("[URL unfurl="true"]http://www.mysite.com/SaveFlash.asp",[/URL] aspResponse, "POST");
}

//Call the function from a submit button
mySubmit.onRelease = sendInfo();

Also you don't need the trailing "&" in your response.write from the ASP page. I can just be
Code:
response.write "writing=Ok"

Hope it helps.

Wow JT that almost looked like you knew what you were doing!
 
Thanks Pix

I finally figured it out early this morning...it is interesting what happens when you get a good nites sleep and feedback from fellow programmers. I commented out what I did, it was really placement of my code..I moved two lines of code to the right place.


[as]
userScore=(numOfQuestionsAnsweredCorrectly*100)/
(numOfQuestionsAnsweredIncorrectly+numOfQuestionsAnsweredCorrectly)
myDate = new Date();
dateTextField = (mydate.getMonth() + "/" + myDate.getDate() + "/" + mydate.getFullYear());

myData = new LoadVars() // i moved this line up above my variables this stopped the blank record entry
myData.final=userScore
myData.date = dateTextField
myData.quiz = quizname
myData.studentname = theuser

myData.onLoad = function(){
if(this.writing="Ok") {
trace ("Submited data was saved")
trace(myData.date); // output: the date
trace(myData.quiz); // output: name of the quiz
trace(myData.final); // output: final score
} else trace("Error in saving submitted data")

trace(this.writing)
trace(dateTextField)
trace(myData.date); // output: the date
trace(myData.quiz); // output: name of the quiz
trace(myData.final); // output: final score
}

myData.sendAndLoad(" myData, "POST"); //I moved this line down here where it should be WHEEWWW
[/as]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top