I made this simple registration form using Flash and I want it to connect to a database in my localhost using PHP, here is my code so far,
function register(evt:MouseEvent):void{
var jpa:URLVariables = new URLVariables;
var varRequest:URLRequest = new URLRequest("register.php");
varRequest.method = URLRequestMethod.POST;
varRequest.data = jpa;
var varLoader:URLLoader = new URLLoader();
varLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
varLoader.addEventListener(Event.COMPLETE, completeHandler);
jpa.fname = form.fname.text;
jpa.lname = form.lname.text;
jpa.uname = form.uname.text;
jpa.pass = form.pass.text;
jpa.age = form.age.text;
jpa.sendRequestReg = "successReg";
varLoader.load(varRequest);
function completeHandler(event:Event):void{
form.msg.text = event.target.data.myVarPHP;
}
}
and this is my code for the php file
<?php
if($_POST['sendRequestReg'] == "successReg"){
$server = "localhost";
$username = "root";
$pass = "";
$dbname = "flashdb";
$d1 = $_POST['fname'];
$d2 = $_POST['lname'];
$d3 = $_POST['uname'];
$d4 = $_POST['pass'];
$d5 = $_POST['age'];
mysql_connect($server,$username,$pass);
mysql_select_db($dbname);
$myQuery = "INSERT INTO users VALUES('$d1', '$d2', '$d3', '$d4', '$d5')";
mysql_query($myQuery) or die (mysql_error(). "AN ERROR");
echo "myVarPHP=Registration Successful";
}
else{
echo "myVarPHP=Failed Try Again";
}
?>
When I click the register button the data won't insert to the database.
By the way, I have a simpler example of this with the same code and it works fine. The data was inserted to the database , but it was made in CS6; this code was made in CS4.
I don't know what the problem is, there is no error in both the PHP file and Flash.