Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / Flash / Data Integration / August 2008



Tip: Looking for answers? Try searching our database.

Flash CS3 <-->PHP<-->MySQL (Almost there!)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mwalimo - 15 Aug 2008 08:49 GMT
I am working on the Flash CS3/PHP/MySQL integration and I think I am almost
there.

Below is the script in my .fla. This script is calling the  register.php
script to pass the variables reg_user (String), reg_pass(String), reg_mail
(String) and sql_type (Integer).

In register.php, I am displaying the results of the DB action and it's showing
&n=0&

The php script is working fine. I have tested by direct placement and value
assignment  ( $reg_user="Tsitsi",
$reg_pass="password",$reg_mail="tsitsi@els.co.za" and $sql_type=1) in the php
script.

So what is wrong with the script below? It seems to be failing to 'transmit'
the values over to the php script?

import flash.display.Sprite;
import flash.net.navigateToURL;
import flash.net.URLRequest;
import flash.net.URLVariables;
var u:String="Tsitsi"
var p:String="password"
var e:String="tsitsi@els.co.zw"
var t:int=1
var variables:URLVariables = new URLVariables();
variables.reg_user=u
variables.reg_pass=p
variables.reg_mail=e
variables.sql_type=t
trace(variables)
var url:String = "http://localhost:81/flash/register.php";
var request:URLRequest = new URLRequest(url);
request.method = URLRequestMethod.POST;
request.data = variables;
navigateToURL(request);
Noelbaland - 16 Aug 2008 08:29 GMT
Hello there,

I think the problem is in how you're capturing the variables in your PHP
script.  I created an example using your Actionscript code and it works fine.  
Instead of hard coding the values for the variables in the script, I created a
registration form and got the values from input textfields.  Once you hit the
SUBMIT button a window opens in the browser and a PHP file catches all the
submitted data and outputs the results.
Below is the code I used in both Flash and PHP files.  You can view the
example here and download the files here.

Hope that helps!

[ACTIONSCRIPT]

import flash.net.*;

submit_btn.addEventListener(MouseEvent.CLICK, submitForm);
reset_btn.addEventListener(MouseEvent.CLICK, resetForm);

function submitForm(event:MouseEvent):void
{
    var u:String = user_txt.text;
    var p:String = pass_txt.text;
    var e:String = email_txt.text;
    var t:int = 1;

    var variables:URLVariables = new URLVariables();
    variables.reg_user = u;
    variables.reg_pass = p;
    variables.reg_mail = e;
    variables.sql_type = t;

    var url:String = "http://localhost/FLASH/register.php";
    var request:URLRequest = new URLRequest(url);
    request.method = URLRequestMethod.POST;
    request.data = variables;
    navigateToURL(request);
}

function resetForm(event:MouseEvent):void
{
    user_txt.text = "";
    pass_txt.text = "";
    email_txt.text = "";
}

[PHP]

<?php

echo "This is the array result that is returned from the Flash form<br><br>";

foreach($_POST as $key=>$val)
{
    echo "$key = $val <br>";
}

echo
"<br>----------------------------------------------------------------------<br><
br>";

echo "Registration results: ";

if(isset($_POST['reg_pass']))
{
    $pass = $_POST['reg_pass'];
    $user = $_POST['reg_user'];
    $email = $_POST['reg_mail'];

    if($pass == "" || $user == "" || $email == "")
    {
        echo "Please fill in all fields! <br>";
    } else {

        // Insert details into database

        echo "Thank you <strong>$user</strong>, you have been registered!
<br>";
    }
}

?>
Mwalimo - 20 Aug 2008 09:13 GMT
Thank you Noelaland
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.