A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Passing data from a dynamic text box to php

  1. #1
    Junior Member
    Join Date
    Aug 2014
    Posts
    4

    Passing data from a dynamic text box to php

    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;
    send_lv.grade = grade.text;
    send_lv.send(submitURL, "POST");
    };

    Php file:

    <html >
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <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>

  2. #2
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    where is your swf located amongst all of this?

    Anyway, without seeing your connectvars.php, as that is where the problem might be or you are adding blank values to the database posssibly.

    PHP Code:
    <?php

    //require_once('connectvars.php');
    $connect mysql_connect("host","user","pass","database");
    $dbase mysql_select_db("database"$connect);

    // Grab the score data from the POST
    $score $_POST['score'];
    $grade $_POST['grade'];

    // Write the data to the database
    $query mysql_query("INSERT INTO transcript (score, grade) VALUES ('$score', '$grade')");
    if (
    $query)
    {
        echo 
    "Success, your percent and grade have been entered.";    
    }
    else
    {
        echo 
    "Sorry, nothing was added.";
    }    
    mysql_close($connect);
    ?>

  3. #3
    Junior Member
    Join Date
    Aug 2014
    Posts
    4
    The swf file is uploaded to the server along with grade.php. As far as the connectvars is concerned, it seems to have no negative effect on the conection.
    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. (This is what is being stored in MySQL)

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

  4. #4
    Junior Member
    Join Date
    Aug 2014
    Posts
    4
    The swf file is uploaded to the server along with grade.php. As far as the connectvars is concerned, it seems to have no negative effect on the conection.
    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. (This is what is being stored in MySQL)

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

  5. #5
    Junior Member
    Join Date
    Aug 2014
    Posts
    4
    The problem has been solved. It turned out I did not define the grade variable as a varchar. After changing it, it worked perfectly.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center