Flash - PHP - Tutorial (not working, guidance needed)

  • Nucleo
  • SausagePorkPie
  • Mastermind
  • User avatar
  • Posts: 2297
  • Loc: UK - England

Post 3+ Months Ago

G'day all.

right, i saw a pretty good video tutorial on the web, showing how to make a flash/php/mysql login application.

I figured i would give it a go, altering it to suit my needs. I am just playing around and trying to get flash to do what i want, to learn AS better.

The Code

This is the AS code in my timeline. pretty basic, creating 2 LoadVars objects, one for holding sent data, one for holding the data received from the php script. The button activates 2 functions, one validates, one submits.

The flash movie is 1 frame, 4 text boxes, a dynamic text box holding the error/success text and a button. Nothing major.

Code: [ Select ]
var sender:LoadVars = new LoadVars();
var receiver:LoadVars = new LoadVars();
var validuser:Boolean = false;
var validpass:Boolean = false;

function validate() {
    if (_root.user.text == "") {
        _root.msg.text = "Please complete the form";
    } else {
        validuser = true;
    }
    if (_root.pass.text == "") {
        _root.msg.text = "Please complete the form";
    } else {
        validpass = true;
    }
}
function submit() {
    if (validuser && validpass) {
        sender.user = _root.user.text;
        sender.pass = _root.pass.text;
        sender.email = _root.email.text;
        sender.location = _root.location.text;
        sender.sendAndLoad("register.php", receiver, "POST");
    }
}
receiver.onLoad = function() {
    if (this.status == "1") {
        _root.msg.text = this.msg;
    } else {
        _root.msg.text = this.msg;
    }
};
btn.onPress = validate;
btn.onRelease = submit;
  1. var sender:LoadVars = new LoadVars();
  2. var receiver:LoadVars = new LoadVars();
  3. var validuser:Boolean = false;
  4. var validpass:Boolean = false;
  5. function validate() {
  6.     if (_root.user.text == "") {
  7.         _root.msg.text = "Please complete the form";
  8.     } else {
  9.         validuser = true;
  10.     }
  11.     if (_root.pass.text == "") {
  12.         _root.msg.text = "Please complete the form";
  13.     } else {
  14.         validpass = true;
  15.     }
  16. }
  17. function submit() {
  18.     if (validuser && validpass) {
  19.         sender.user = _root.user.text;
  20.         sender.pass = _root.pass.text;
  21.         sender.email = _root.email.text;
  22.         sender.location = _root.location.text;
  23.         sender.sendAndLoad("register.php", receiver, "POST");
  24.     }
  25. }
  26. receiver.onLoad = function() {
  27.     if (this.status == "1") {
  28.         _root.msg.text = this.msg;
  29.     } else {
  30.         _root.msg.text = this.msg;
  31.     }
  32. };
  33. btn.onPress = validate;
  34. btn.onRelease = submit;


The PHP script
PHP Code: [ Select ]
<?php
 
$username = "xxxx";
 
$password = "xxxx";
 
$hostname = "localhost";   
 
$db = "xxxx";
 
$dbh = mysql_connect($hostname, $username, $password, $db)
 
   or die("&status=0&msg=DB Error");
 
 
 
$user = $_POST['user'];
 
$pass = $_POST['pass'];
 
$email = $_POST['email'];
 
$location = $_POST['location'];
 
 
 
if ($user = " ") {
 
echo "&status=0&msg=No data posted";
 
exit;
 
}
 
 
 
$sql = "INSERT INTO users (username, password, email, location) VALUES ($user, $pass, $email, $location)";
 
if ($sql) {
 
   mysql_query($sql);
 
   echo "&status=1&msg=Think it worked";
 
      } else {
 
      die("&status=0&msg=Query Error");
 
   }
 
mysql_close($dbh);
 
?>
  1. <?php
  2.  
  3. $username = "xxxx";
  4.  
  5. $password = "xxxx";
  6.  
  7. $hostname = "localhost";   
  8.  
  9. $db = "xxxx";
  10.  
  11. $dbh = mysql_connect($hostname, $username, $password, $db)
  12.  
  13.    or die("&status=0&msg=DB Error");
  14.  
  15.  
  16.  
  17. $user = $_POST['user'];
  18.  
  19. $pass = $_POST['pass'];
  20.  
  21. $email = $_POST['email'];
  22.  
  23. $location = $_POST['location'];
  24.  
  25.  
  26.  
  27. if ($user = " ") {
  28.  
  29. echo "&status=0&msg=No data posted";
  30.  
  31. exit;
  32.  
  33. }
  34.  
  35.  
  36.  
  37. $sql = "INSERT INTO users (username, password, email, location) VALUES ($user, $pass, $email, $location)";
  38.  
  39. if ($sql) {
  40.  
  41.    mysql_query($sql);
  42.  
  43.    echo "&status=1&msg=Think it worked";
  44.  
  45.       } else {
  46.  
  47.       die("&status=0&msg=Query Error");
  48.  
  49.    }
  50.  
  51. mysql_close($dbh);
  52.  
  53. ?>


now then, i couldn't for the life of me get this to work, it just seems to fail. I then added a check to see if the $user variable exists, it doesn't. This means that flash isn't posting the data from the movie to the php script.

anyone know why no data is being submitted to the php script? I am doing this on my local machine, could that have anything to do with it?

Thanks all
  • classified
  • Expert
  • Expert
  • User avatar
  • Posts: 540
  • Loc: Bahrain

Post 3+ Months Ago

did u try tracing the user variable from flash itself ?
  • Nucleo
  • SausagePorkPie
  • Mastermind
  • User avatar
  • Posts: 2297
  • Loc: UK - England

Post 3+ Months Ago

not sure what you mean by tracing. There is error handling for the user variable (the text box) ensures that there is some content.
  • classified
  • Expert
  • Expert
  • User avatar
  • Posts: 540
  • Loc: Bahrain

Post 3+ Months Ago

i'll have 2 try it to debug ...
see how it goes tomowoz ...
  • Nucleo
  • SausagePorkPie
  • Mastermind
  • User avatar
  • Posts: 2297
  • Loc: UK - England

Post 3+ Months Ago

ok, got it working, basically the php script was written wrong. got a friend to take a look at it. Now the script is :

PHP Code: [ Select ]
<?php
 
$username = "....";
 
$password = "....";
 
$hostname = "....";  
 
$db = "...";
 
   
 
mysql_connect($hostname,$username,$password) or die(mysql_error());
 
mysql_select_db($db) or die(mysql_error());
 
 
 
$user = $_POST['user'];
 
$pass = $_POST['pass'];
 
$email = $_POST['email'];
 
$location = $_POST['location'];
 
 
 
if ($user)
 
{
 
$sql = mysql_query ("INSERT INTO users (`username`, `password` , `email` , `location`) VALUES ('$user', '$pass', '$email', '$location')");
 
echo "&status=1&msg=IT *peach* WORKED";
 
}
 
 
 
exit;
 
?>
  1. <?php
  2.  
  3. $username = "....";
  4.  
  5. $password = "....";
  6.  
  7. $hostname = "....";  
  8.  
  9. $db = "...";
  10.  
  11.    
  12.  
  13. mysql_connect($hostname,$username,$password) or die(mysql_error());
  14.  
  15. mysql_select_db($db) or die(mysql_error());
  16.  
  17.  
  18.  
  19. $user = $_POST['user'];
  20.  
  21. $pass = $_POST['pass'];
  22.  
  23. $email = $_POST['email'];
  24.  
  25. $location = $_POST['location'];
  26.  
  27.  
  28.  
  29. if ($user)
  30.  
  31. {
  32.  
  33. $sql = mysql_query ("INSERT INTO users (`username`, `password` , `email` , `location`) VALUES ('$user', '$pass', '$email', '$location')");
  34.  
  35. echo "&status=1&msg=IT *peach* WORKED";
  36.  
  37. }
  38.  
  39.  
  40.  
  41. exit;
  42.  
  43. ?>


changing
PHP Code: [ Select ]
mysql_connect($hostname,$username,$password) or die(mysql_error());
 
mysql_select_db($db) or die(mysql_error());
  1. mysql_connect($hostname,$username,$password) or die(mysql_error());
  2.  
  3. mysql_select_db($db) or die(mysql_error());


to

PHP Code: [ Select ]
mysql_connect($hostname,$username,$password) or die("&msg=" . mysql_error());
 
mysql_select_db($db) or die("&msg=" . mysql_error());
  1. mysql_connect($hostname,$username,$password) or die("&msg=" . mysql_error());
  2.  
  3. mysql_select_db($db) or die("&msg=" . mysql_error());


to help with error checking =)
  • luisrps
  • Born
  • Born
  • luisrps
  • Posts: 3

Post 3+ Months Ago

any 1 knows how fill a combobox with mysql data ?

http://www.ozzu.com/flash-forum/how-put-mysql-data-into-combobox-t69878.html
  • classified
  • Expert
  • Expert
  • User avatar
  • Posts: 540
  • Loc: Bahrain

Post 3+ Months Ago

Nucleo wrote:
ok, got it working, basically the php script was written wrong. got a friend to take a look at it. Now the script is :

PHP Code: [ Select ]
<?php
$username = "....";
$password = "....";
$hostname = "....";  
$db = "...";
   
mysql_connect($hostname,$username,$password) or die(mysql_error());
mysql_select_db($db) or die(mysql_error());
 
$user = $_POST['user'];
$pass = $_POST['pass'];
$email = $_POST['email'];
$location = $_POST['location'];
 
if ($user)
{
$sql = mysql_query ("INSERT INTO users (`username`, `password` , `email` , `location`) VALUES ('$user', '$pass', '$email', '$location')");
echo "&status=1&msg=IT *peach* WORKED";
}
 
exit;
?>
  1. <?php
  2. $username = "....";
  3. $password = "....";
  4. $hostname = "....";  
  5. $db = "...";
  6.    
  7. mysql_connect($hostname,$username,$password) or die(mysql_error());
  8. mysql_select_db($db) or die(mysql_error());
  9.  
  10. $user = $_POST['user'];
  11. $pass = $_POST['pass'];
  12. $email = $_POST['email'];
  13. $location = $_POST['location'];
  14.  
  15. if ($user)
  16. {
  17. $sql = mysql_query ("INSERT INTO users (`username`, `password` , `email` , `location`) VALUES ('$user', '$pass', '$email', '$location')");
  18. echo "&status=1&msg=IT *peach* WORKED";
  19. }
  20.  
  21. exit;
  22. ?>


changing
PHP Code: [ Select ]
mysql_connect($hostname,$username,$password) or die(mysql_error());
mysql_select_db($db) or die(mysql_error());
  1. mysql_connect($hostname,$username,$password) or die(mysql_error());
  2. mysql_select_db($db) or die(mysql_error());


to

PHP Code: [ Select ]
mysql_connect($hostname,$username,$password) or die("&msg=" . mysql_error());
mysql_select_db($db) or die("&msg=" . mysql_error());
  1. mysql_connect($hostname,$username,$password) or die("&msg=" . mysql_error());
  2. mysql_select_db($db) or die("&msg=" . mysql_error());


to help with error checking =)

sorry i been busy about ...
have u got the files ?

Post Information

  • Total Posts in this topic: 7 posts
  • Users browsing this forum: No registered users and 2 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.