Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

New Here ,
Aug 01, 2014 Aug 01, 2014

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>

TOPICS
ActionScript
1.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Aug 05, 2014 Aug 05, 2014

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.

Translate
Community Expert ,
Aug 01, 2014 Aug 01, 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;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 01, 2014 Aug 01, 2014

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 01, 2014 Aug 01, 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);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 03, 2014 Aug 03, 2014

I just tried what you suggested and I can not even get it to trace anything.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 03, 2014 Aug 03, 2014

I tried it again and it said both variables were undefined. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 03, 2014 Aug 03, 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'} }

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 03, 2014 Aug 03, 2014

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

and remove that getURL function

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 03, 2014 Aug 03, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 03, 2014 Aug 03, 2014

I was pulling my hair after i changed lines in my code:

submit_btn.onRelease = function() {

  if (collect_numba.text != '') {

        //Entries ok - submit the data

var sendVar:LoadVars = new LoadVars();

var receiveLV:LoadVars=new LoadVars();

  sendVar.collect_numba = collect_numba.text;

  sendVar.sendAndLoad("goto.php", receiveLV, "POST");

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

  } else {

  error_box.text = 'Fill fields correctly';

  }

};

I know you said i should make changes..which i did.the reason for the line --> getURL() was just to test if Php has any info in the memory. But when i tried to echo collect_numba in php, nothing was displayed.I will be stuck here for ever as i am not ready to go code in AS3 just for this reason. Im still awaiting that generous help pls.. Anyone

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 04, 2014 Aug 04, 2014

it's too complicated to deal with two posters in the same thread.  pen_test, you should start your own thread if the following doesn't help you:

i recommend using the following:

var send_lv:LoadVars=new LoadVars();

var receive_lv:LoadVars=new LoadVars();

var submitURL:String = "grade.php";

receive_lv.onData=function(src:String){

trace("received: "+src);  // this will help with debugging

}

submit_button.onRelease = function(){

send_lv.score = percent.text;

send_lv.grade = grade.text;

trace(sending :"+percent.text +" "+grade.text);  // make sure your textfields are correct

send_lv.sendAndLoad(submitURL, receive_lv,"POST");

};

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 04, 2014 Aug 04, 2014

I strongly apologize to BigLewie..Forgive my intruding question as i didn't mean to steal your thread.Thank you Kglad for such decency..I greatly appreciate the support.I shall whence-forth be listening/watching to see how the thread turns out.. in the meantime,i am off to try this new direction..Thanks!!! 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 05, 2014 Aug 05, 2014

There is no need to apologize. It's all good.

Sent from my Galaxy S®III

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 05, 2014 Aug 05, 2014

@ pen_test, i'll watch for your thread.  but start with the code in message 11 (adapted to your situation).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 05, 2014 Aug 05, 2014

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.)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 05, 2014 Aug 05, 2014

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 03, 2014 Aug 03, 2014

I'm still working on it, but I'll keep you up to date.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 06, 2014 Aug 06, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 07, 2014 Aug 07, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 07, 2014 Aug 07, 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 07, 2014 Aug 07, 2014
LATEST

sounds good.

p.s. you should seriously consider moving to as3 instead of continuing to use as2.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines