Thursday, June 28, 2012

[Action Script] Connecting Flash to Php/MySQL June,2012

Hello. I am having a problem connecting flash to php/mysql. Here is my flash code:

Code: var lvSend:LoadVars = new LoadVars();
var lvReceive:LoadVars = new LoadVars();

register_button.onRelease = function() {
        var valid:Boolean = validateForm();
        if(valid){
        //gather information and put in loadvars object
        lvSend.username = username1.text;
        lvSend.password = password1.text;
        lvSend.email = email1.text;
        lvSend.sendAndLoad("register.php", lvReceive, "POST");
        username1.text = "";
        password1.text = "";
        email1.text = "";
        gotoAndStop(1);
}
}
        lvReceive.onLoad = function(success:Boolean) {
if (success) {
    trace("ok");
}
else {
    trace("error");
    }
        }
function validateForm():Boolean{
        if(username1.text == "" || password1.text == "" || email1.text == ""){
                return false;               
}
        return true;
}Here is my php code:
Code: <?PHP
//Database Information
$dbhost = "xxxxxxxx";
$dbname = "xxxxxxxxx";
$dbuser = "xxxxxxxx";
$dbpass = "xxxxxxxx";
//Connect to Database
mysql_connect($dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname)or die(mysql_error());
$email = $_POST['email'];
$username = $_POST['username'];
$password = $_POST['password'];
//If no errors present with the username use a query to insert the data into the database.
$query = "INSERT INTO users(email,username,password)
VALUES('$email','$username','$password')";
mysql_query($query)or die(mysql_error());
mysql_close();
//Lets check to see if the username already exists
$checkuser = mysql_query("SELECT username FROM users WHERE username='$username'");
$username_exist = mysql_num_rows($checkuser);
if($username_exist > 0){
echo "I'm sorry but they username you have chosen is already in use. Please pick another.";
unset($username);
include 'play.swf';
exit();
}
//If no errors present with the username use a query to insert the data into the database.
$query = "INSERT INTO users(email, username, password)
VALUES('$email', '$username', '$password')";
mysql_query($query)or die(mysql_error());
mysql_close();
echo "You have successfully been registered!";
//Mail user their information
$yoursite = 'MonkeyIsland';
$webmaster = 'xxxxxxxxx';
$youremail = 'xxxxxxxx';
$subject = "You have been registered";
$message = "Dear $username, you have been successfully registered at xxxxxx!
Here is your login information:
Username = $username
Password = $password
Please don't share this information with anyone.
Thanks,
$webmaster";
mail($email, $subject, $message, "From: $yoursite <$youremail>\nX-Mailer:PHP/" . phpversion());
echo "Your information has been mailed to your email address.";
?>I was wondering what could possibly be the problem. My button works and all, its just that it doesn't send it to the database. Can anyone give me any sort of help? I'll take any answers. Thanks!
Connecting Flash to Php/MySQL

Related Post



0 comments: