1 Replies - 945 Views - Last Post: 04 January 2011 - 07:11 AM

#1 stunningstylez  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 03-January 11

CS3 to PHP to MySQL issue

Posted 03 January 2011 - 09:16 PM

I have searched for a solution over many forums and none of the code seems to work. I cannot get AS3 to work with a php script.
I am trying to create a registration form in AS3
and then have that information go to mysql database when
the submit button is pressed.

Here is part of the AS3 code:

var variables:URLVariables = new URLVariables;
var varSend:URLRequest = new URLRequest("register.php");
varSend.method = URLRequestMethod.POST;
varSend.data = variables;
var varLoader:URLLoader = new URLLoader;
varLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
variables.userName = user_txt.text;
variables.userPass = pass_txt.text;
variables.userEmail = email_txt.text;

Here is the php script "register.php":


$db_host = "localhost";
$db_username = "root"; 
$db_pass = ""; 
$db_name = "userregister";

mysql_connect("$db_host","$db_username","$db_pass" ) or die ("could not connect to mysql");
mysql_select_db("$db_name") or die ("no database");

$senderName = $_POST['userName'];
$senderPass = $_POST['userPass'];
$senderEmail = $_POST['userEmail'];

$sqlCommand = "INSERT INTO user (username, password, email)
VALUES('$senderName','$senderPass','$senderEmail') ";

$query = mysql_query($sqlCommand) or die (mysql_error());

$my_msg = "Thanks $senderName, all data has been sent.";

echo "return_msg=$my_msg";


Is This A Good Question/Topic? 0
  • +

Replies To: CS3 to PHP to MySQL issue

#2 FliP1992  Icon User is offline

  • D.I.C Head

Reputation: 14
  • View blog
  • Posts: 200
  • Joined: 14-June 07

Re: CS3 to PHP to MySQL issue

Posted 04 January 2011 - 07:11 AM

This is the snippet that i always use when connecting to a script file as I can check for errors that the php file may output. For example if the user enters the wrong username/password it will catch the error and display it back in the Flash file.

Its simple to understand just all im using is GET instead of POST. all the GET data that your sending goes in the "URLRequest" variable. Use a full URL.
function sendData()
	var request:URLRequest = new URLRequest("http://www.yoururl.com/register.php?userName="+user_txt.text+"&userPass="+pass_txt.text+"&userEmail="+email_txt.text);
	request.method = URLRequestMethod.GET;
	var urlloader:URLLoader = new URLLoader();
	urlloader.dataFormat = URLLoaderDataFormat.VARIABLES;
	urlloader.addEventListener(Event.COMPLETE, loadData);
function loadData(evt:Event) {
		trace("System: Data sent with no errors");
		trace("System: Error found");

Once the page has been fully loaded the loadData function will run and all that does is check for any errors that a sent back from the script by looking for errorhandler on the content on the page.
echo "errorhandler=None";

Hope this is helpful

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1