-1

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.

MasterAM
  • 16,283
  • 6
  • 45
  • 66
Patricio
  • 11
  • 1
  • 9
  • Is there an error message? Does it insert anything? The wrong thing? The right thing to the wrong place? Echo out your generated SQL and run it in the database - does that work? – andrewsi Apr 12 '13 at 17:10
  • phpmyadmin is a database management suite. it is not a database. flash does not have database drivers, and cannot talk to mysql. you need to set up a webservice (e.g. in php) that takes Flash data and sends it to mysql. read up on flash remoting for such things. – Marc B Apr 12 '13 at 17:10
  • sir @andrewsi there is no error msg within php side, for testing i run the swf file through the browser, so that it can communicate to the phpmyadmin, i really dont now whats wrong, but in my other example the database insertions works fine,, i cant edit the first example though it is made using flash cs6, – Patricio Apr 12 '13 at 17:17
  • sir @MarcB it does work, if you want i can send you my sample regform in flash, together with the php file so you can test it, however this new code using cs4 doesnt work – Patricio Apr 12 '13 at 17:18
  • @Patricio - in that case, what about checking the SQL you're generating is valid? – andrewsi Apr 12 '13 at 17:19
  • found the freakin problem! the filename of the php file is "registration" but the one that im callin in the flash code is "register.php" its working now and it inserts the data to the phpmyadmin... anyways guys thank you for your response, this kind of mistakes pisses me off, maybe my brain is little bit to cloudy now, its 2am here... thanks again! *hands down* :D – Patricio Apr 12 '13 at 17:27

1 Answers1

0

Make sure your (XAMP or WAMP ?) is running and to test this set up paste your register.php in htdocs folder(I use XAMP) and change the URLRequest like so,

var varRequest:URLRequest = new URLRequest("http://localhost/register.php");

This worked for me (using XAMP).

Best luck.

Rajneesh Gaikwad
  • 1,193
  • 2
  • 14
  • 30