Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Flash, PHP and MySQl databases

Status
Not open for further replies.

squiggles121

Technical User
Aug 17, 2006
14
GB
Hiya

I'm making a website for kids and on the profile page there is a character that you can change the clothes of (there is a Flash movie clip for Hats, Eyes, Hair etc. with a nextFrame and prevFrame arrow to change the colour of the items respectively).

I need to connect this in PHP to a database so that you can save the clothes that the user picks (or the current frame of each movie clip)and this is then saved as their profile picture.

As it stands, I have created a variable on each frame of say the hatColour movie clip to set a variable (frame 1 hatColour="red"; frame 2 hatColour="blue" and so on)
The Actions layer on the main timeline then has

Code:
var hatColour:String ="";
vars = new LoadVars();
save_check = new LoadVars();
save_btn.onRelease = function(){
	vars.hatColour=hatColour;
	save_check.onLoad=function(){
		if(this.response == "passed"){
			_root.gotoAndStop(2);
		}else{
			_root.gotoAndStop(3);
		}
	}
	vars.sendAndLoad("save_vars.php", save_check, "POST");
};

There are then 2 PHP files; one to save the animation (save_vars.php) and one to load it back (load_vars.php) with the swf file on edit.php.

I could post the code but this post is getting really long already! Basically save_vars.php connects to the database, ensures the user is logged in and then has the code:

Code:
<?php
$name = $_POST["name"];
$hatColour = $_POST["hatColour"];
mysql_select_db($database_db, $db);

$insert = "UPDATE users SET ( HatColour='".$hatColour."') WHERE Name='".$UserName."'";
mysql_query($insert,$db)or die(mysql_error());

echo "response=passed";
?><?php
mysql_free_result($Recordset1);
?>

to update the user's profile in the database.

When run and the user hits the save button it says failed (as it has gone to frame 3 of the swf) and the database is not updated.

Any thoughts would be much appreciated as I've lost lots of sleep over this! :)
 
Hey

Thanks for the advice.

I changed the last line of AS from

vars.sendAndLoad("save_vars.php", save_check, "POST");

to

vars.sendAndLoad("save_vars.php", vars, "POST");

but now instead of displaying the failed screen on the swf it just sticks with the status 'transferring data to server' and doesn't appear to be doing anything.

Is there anything else that I should double-check or should this coding work and my server is just being temperamental?

Many thanks :)
 
var hatColour:String ="";
save_btn.onRelease = function(){
vars = new LoadVars();
vars.hatColour=hatColour;
vars.name=name;
vars.onLoad=function(){
if(this.response == "passed"){
_root.gotoAndStop(2);
}else{
_root.gotoAndStop(3);
}
}
vars.sendAndLoad("save_vars.php", vars, "POST");
};
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top