Jump to content

Passing variables to mysql from flash via PHP


carl_laruso

Recommended Posts

Hey guys i'm trying to get 2 variables out of a flash game into a mysql dB via PHP

 

var1 an email

var2 a score

 

the problem is my flash movie keeps saying "undefined" and the variables are not passed to the MySQL data base

 

fire fox tamper says that POST_DATA is chucking out a score as var2 and a email as var1

 

my PHP code is below (i've blanked out the user/password stuff)

 

 

<?

$mysqlhost = "*********";

$mysqluser = "*********";

$mysqlpass = "*********";

$mysqldatabase = "*********";

mysql_pconnect($mysqlhost, $mysqluser, $mysqlpass);

mysql_select_db($mysqldatabase);

$name = strip_tags($_REQUEST["var1"]);

$score = strip_tags($_REQUEST["var2"]); 

$query = "INSERT INTO scores_ast VALUES ('$name','$score')";

mysql_query($query);

?>

 

can anyone see anything wrong with it or does any one have any ideas as to why its not working?

 

C.

Is your insert statement correct? You seem to be inserting a record with 2 columns in a table which has 3 columns. Use null for id since it is an auto_increment column.

 

And also, rmb to use mysql_real_escape_string() around your input variables.

Is your insert statement correct? You seem to be inserting a record with 2 columns in a table which has 3 columns. Use null for id since it is an auto_increment column.

 

And also, rmb to use mysql_real_escape_string() around your input variables.

Or just define which values are being inserted with the query, for example:

 

$query = "INSERT INTO `scores_ast` (`score`, `name`) VALUES ('$name','$score')";

hey guys

 

thank you so much for your help....... just about to try a new insert statement

 

here is my flash code - there is a lot of it but i think this is the most relevant

______________________________________________________________________

 

screen_gameover.dyn_feedback.text = ""; // Clear the reporting field.

datatarget = "**************************************************"; // this is correct

function collectdata():Void{

capsname = screen_gameover.theinput.text.charAt(0).toUpperCase()+screen_gameover.theinput.text.slice(1); // Force a capital on the gramatically lazy user

gamedata = new LoadVars();

gamedata.var1 = capsname;

gamedata.var2 = _root.score;

trace (gamedata);

trace ("==============================");

}

 

screen_gameover.btn_submit.onRelease = function(){

if (screen_gameover.theinput.text == "" || screen_gameover.theinput.text == initmsg){

screen_gameover.dyn_feedback.text = "Please Enter Your E-Mail"; // Tell user

cleartimer = setInterval(clearmsg, 2500); // So message above disappears after 4 seconds

} else { // Only send if there is some text

screen_gameover.btn_submit._visible = false;

screen_gameover.btn_restart._visible = true; // now alow the user to restart the game

collectdata();

gamedata.sendAndLoad(datatarget,gamedata,"post");

gamedata.onLoad = function(ok) {

if (ok) {

screen_gameover.dyn_feedback.text = this.msg;

Key.removeListener(keyListener);

} else {

screen_gameover.dyn_feedback.text = "There was an error sending the data!";

screen_gameover.btn_submit._visible = true;

}

}

_root.clearfield(); // Remove all badies again, just to be sure.

}

}

 

 

ok i tried Joshua4550's insert statement but the flash game is still reporting "undefined"

 

 

the PHP now looks like this:

 

 

<?

$mysqlhost = "**********";

$mysqluser = "**********";

$mysqlpass = "**********";

$mysqldatabase = "**********";

mysql_pconnect($mysqlhost, $mysqluser, $mysqlpass);

mysql_select_db($mysqldatabase);

$name = strip_tags($_REQUEST["var1"]);

$score = strip_tags($_REQUEST["var2"]); 

$query = "INSERT INTO `scores_ast` (`score`, `name`) VALUES ('$name','$score')";

mysql_query($query);

?>

 

DOH!!!

 

also FYI i am copying and pasting the DB name and user etc directly

just out of interest where is the word "undefined" coming from?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.