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”);
};
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>