Skip to main content
BigLewie
Participating Frequently
August 1, 2014
Answered

Problem passing a variable from a dynamic text field to php (Flash 8)

  • August 1, 2014
  • 3 replies
  • 1170 views

I am currently working on a flash file where a person enters
their score into an input text box with an instance name of score and then it
converts it to a percentage and grade. 
The swf file displays the grade and percentage in two dynamic text boxes
with instance names of percent and score. 
That part gives me no trouble.
The main objective is to pass the percent and score to a php file called
grade.php and then store both variables in MySQL. 

After uploading the files to a server, I run the swf file and
it seems like everything works.  But when
I check the MySQL file, I notice that a row has been inserted, but no score or
grade is entered.   I can not figure out
what the problem is.  Can anyone assist
me with this?

Here the Actionscript 2.0 code and the php file:

function findPercent() {

percent.text = (score.text * 100) / 100;

if (percent.text >= 90) {

grade.text = "A";

     }  else if (percent.text < 90 &&  percent.text >= 80){

grade.text = "B";

     else
if (percent.text < 80 && percent.text >= 70){

grade.text = "C";

     }  else if (percent.text < 70 && percent.text >= 60){

grade.text = "D";

     }   else if (percent.text < 60){

grade.text = "F";

}

}

submit_button.onRelease = function(){

submitURL = "grade.php";

 

// create a LoadVars object instance and populate it.

send_lv = new LoadVars();

send_lv.score = "percent.text";    //  (Note: when I used the input text box as .score.text, it displayed  in MySQL)

send_lv.grade = "grade.text";

send_lv.send(submitURL, "POST");

 

};

(grade.php)

<html>

<head>

<title>Grades: Add Your Grade and Score</title>

</head>

<body>

<h2>Grade Display</h2>

<?php

require_once('connectvars.php');

// Connect to the database

$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);

// Grab the score data from the POST

$score = $_POST['score'];

$grade = $_POST['grade'];

// Write the data to the database

$query = "INSERT INTO transcript (score, grade) VALUES ('$score', '$grade')";

mysqli_query($dbc,$query);

mysqli_close($dbc);

?>

<hr />

</body>

</html>

This topic has been closed for replies.
Correct answer kglad

I made a few changes to grade.php  by adding two echo statements to see if the varibles were passing and it is being displayed in the output.  Also, I noticed that the score I entered is being stored in the database, but not the grade.  This has me stumped.  Is there any way to attach the fla file so you could see the set up?  For what it is worth, I could give the instance names of the three text boxes.

                                                        The input text box has an instance name of score. 

                                                        The first dynamic text box is titled percent and the second grade.

            (After I click the convert button, the percent and grade are displayed in the two dynamic text boxes.)


if you use the trace statements as suggested in message 4 and those trace statements match your expectations, the problem will be in your php file.

i don't see a problem with your php code, but there's no way (in this forum) to check whether your db columns are score and grade and whether they have the correct data type.

p.s. i don't download and correct files unless i'm hired.  free help i only offer via the adobe forums.

3 replies

BigLewie
BigLewieAuthor
Participating Frequently
August 7, 2014

The issue has been solved.  It turned out that I defined the grade variable in the database as an INT instead of VARCHAR.  Now it works perfectly.  But thanks, kglad, for your help in the matter.

kglad
Community Expert
Community Expert
August 7, 2014

you're welcome.

but i changed my response to the correct answer because that's exactly what i said.  and you should also mark helpful responses.

BigLewie
BigLewieAuthor
Participating Frequently
August 7, 2014

No problem. I thought I marked yours, as well. But l'll be more more mindful in the future.

Sent from my Galaxy S®III

pen_test
Participating Frequently
August 3, 2014

Biglewie: Were you able to make your variable register to the database? I am having similar probs. But i still cant figure out why Kglad wonderful numerous explanation wont sort me out .I ll just paste a bit of my AS2 code here. I'm most definite its where my problem is arising from..

EDIT: I tested my Php code n realized NO DATA was received from AS.

submit_btn.onRelease = function() {

  if (collect_numba.text != '') {

                               //Entries ok - submit the data

var    MyLoadVars=new LoadVars();

MyLoadVars.collect_numba = "collect_numba.text";

MyLoadVars.sendAndLoad("goto.php",MyLoadVars,"POST");

   getURL ("goto.php", "_blank", "POST");

                                               }

else {error_box.text = 'Fill fields correctly'} }

kglad
Community Expert
Community Expert
August 3, 2014

you have the same error as the op.  remove those tf.text quotes.

and remove that getURL function

pen_test
Participating Frequently
August 4, 2014

Sure,thanks.But i had a different code until i started to practice with everyone's else example. The original code i am using is -->

submit_btn.onRelease = function() {

    if (collect_numba_txt.text != '') {

        error_box.text = 'Thanks and GoodLuck winning!';

    } else {

        error_box.text = 'Enter no. properly';

            }

MyLoadVars=new LoadVars();

MyLoadVars.onLoad=Function(ok)    //assuming all went well

            MyLoadVars.theName=collect_numba_txt.text       

MyLoadVars.sendAndLoad('goto.php',MyLoadVars,'POST');  };

However, this code updates an empty row in my database Table. Like i mentioned in my previous post(Edit), i found out no variable is being passed to Php whence the probable reason for an empty row update in the database. Once again, i know its AS making my life/code miserable,not Php.

kglad
Community Expert
Community Expert
August 1, 2014

those quotes are problematic.  try:

send_lv.score = percent.text;    //  (Note: when I used the input text box as .score.text, it displayed  in MySQL)

send_lv.grade = grade.text;

BigLewie
BigLewieAuthor
Participating Frequently
August 1, 2014

I did that and I am still getting the same result.

kglad
Community Expert
Community Expert
August 1, 2014

then use the trace function to see if the problem is in your actionscript:

send_lv.score = percent.text;

send_lv.grade = grade.text;

trace("send_lv "+send_lv.score+" "+send_lv.grade);