Groups | Blog | Home
all groups > flash data integration > october 2006 >

flash data integration : Flash<>PHP<>mySQL


Djgary
10/13/2006 2:04:38 PM
i need to be able to do the following....

type into flash a membership number....then send the data out to a php file
(via a submit button)...the php in-turn will query the mySQL database and find
the membership number and their corresponding details (their name, their date
of birth and their address)...the php then will feed the results back into the
flash file and the flash file will display them (the membership number, their
name, their date of birth and their address) in dynamic text fields on another
frame of the flash movie.

i have looked at many examples on the net but none of them seem to do the
above process...(either they don't send the information back to flash or they
don't query a mySql database or most commonalty they are a login in system and
only send a boolean results back to flash)

can anyone suggest a tutorial/book/code/anything that could help me solve this
problem...?

Once i have cracked this i will promise to make a tutorial detailing exactly
how..who and why! ...because I'm sure other people NEED to know this!

thanks in advance

gary:confused;
Mwalimo
10/14/2006 1:28:22 PM
Indeed, I too need the same help.

I have tried the tutorial on data integration, Guestbook. The client(flash)
side is very siomple and straightforward.

However, the [b]server[/b](php) side is not explained. The three scripts on
the server side are:
1. [b]bg_insert.php[/b] used to insert a record in an sql database
2. [b]bg_select.php[/b]) used to read records from an sql database
3. [b]styles.css[/b] used to format the display of records selected by
bg_select.php

The above files are seating on http://www.helpexamples.com/flash/guestbook/.

Does anyone know how to view the source code of these scripts. They may
provide the answer for Djgary and I.

Thanks
Neotropic
10/18/2006 6:45:00 PM
Hopefully this will give you a jump start. Im actually sad to see the lack of
response on an actual company website. Guess money in the pockets is more
important that the people that use the product. one would think you would get
the most input from the company itself.

Any ways... I'm upset since Adobe took Macromedia, performance wise. But thats
another topic.

Now.... the code. Im gonna section this out.
- ActionScript
- PHP Code
- DB Class Code

(ROFL! I reeeally have no idea whats up with this board doing this below to
the URL)
scriptsUrl = "http://www.url.to/guestbook.php?action=";
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::://
// ActionScript / GETTING DATA
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::://
phpCall(displayMultiple, "multiple");
//
function displayMultiple() {
_data = myResult;
delete myResult;
messageList = Array();
for (var i = 0; i<=_data.total_lines; i++) {
messageList.push({gname:_data["name_"+i], gmessage:_data["message_"+i]});
}
trace(gname[0].gname);
trace(gname[0].gmessage);
}
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::://
phpCall(displaySingle, "single");
//
function displaySingle() {
_data = myResult;
delete myResult;
guest_name = _data.name;
guest_message = _data.message;
// OR
guest_name = _data["name"];
guest_message = _data["message"];
//
trace(guest_name);
trace(guest_message);
}
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::://
// EXELLENT WAY FOR CALLING SCRIPTS AND RETURNING DATA
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::://
function phpCall(returnFunc, action) {
var returnObj = this;
returnObj.returnFunc = returnFunc;
var phpRequest = new LoadVars();
phpRequest.onLoad = function(success) {
if (success) {
returnObj.myResult = phpRequest;
false;
delete phpRequest;
returnObj.returnFunc();
} else {
trace("failed");
}
};
phpRequest.sendAndLoad(scriptsUrl+action, phpRequest, "POST");
}
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::://
// ActionScript / SAVING DATA
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::://
saveMessage(poster_name, poster_message);
//
function saveMessage(poster_name, poster_message) {
var phpRequest = new LoadVars();
phpRequest.onLoad = function(success) {
if (success) {
someFunction();
delete phpRequest;
} else {
trace("failed");
}
};
phpRequest.action = insert_post;
phpRequest.pmessage = poster_message;
phpRequest.pmessage = poster_message;
phpRequest.sendAndLoad(scriptsUrl, phpRequest, "POST");
}
Neotropic
10/18/2006 6:45:32 PM
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::://
// PHP - RETRIEVE
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::://
// Returning Multiple lines
if($_POST['action'] == 'multiple'){
$count = 0;
$output = '';
$query = $db->query("SELECT name,message FROM guestbbok WHERE name != '' &&
message != ''");
while ($lines = $db->fetch_array($query)) {
$output .= "&name_".$count."=" . $lines['name'];
$output .= "&message_".$count."=" . $lines['message'];
$count++;
}
// Now echo it back:
echo "&result=true&total_lines=".$count.$output; // If no ouput we still need
to return something, anything to tell Flash, "Hey. WERE DONE!"
exit;
}

if($_POST['action'] == 'single'){
$getinfo = $db->query("SELECT name,message FROM guestbbok WHERE name != '' &&
message != ''");

if($getinfo['name']){
echo "&result=true&name=" . $getinfo['name'] . "&message=" .
$getinfo['message']; // If no ouput we still need to return something, anything
to tell Flash, "Hey. WERE DONE!"
} else {
echo "&result=no data";
}
exit;

}


//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::://
// PHP - INSERT
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::://
if($_POST['action'] == 'insert_post'){
$db->unbuffered_query("INSERT INTO guestbook (name,message) VALUES ('" .
$_POST['poster_name'] . "', '" . $_POST['poster_message'] . "')");
echo "&result=true";
exit;
}
Neotropic
10/18/2006 6:45:48 PM


//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::://
// PHP CLASS FILE
<?php
class db {
var $querynum = 0;
var $databhostname = 'localhost';
var $databname;
var $databusername = 'root';
var $databpassword;
var $fontatr = 'size="2" face="Verdana, Arial"';
var $pconnect = 0;

function connect($databhostname, $databname, $databusername,
$databpassword)
{
if ($this->pconnect != 0) {
$sql_link = @mysql_pconnect($databhostname, $databusername,
$databpassword);
} else {
$sql_link = @mysql_connect($databhostname, $databusername,
$databpassword);
}
if ($sql_link === false) {
echo "<div align=\"center\"><font $this->fontatr>[B]Error
establishing a database connection![/B]</font>[NUM][LI]<font $this->fontatr>Are
you sure you entered the correct user/password?</font>[LI]<font
$this->fontatr>Are you sure that you have typed the correct
hostname?</font>[LI]<font $this->fontatr>Are you sure that the database server
is running?</font>[/NUM]<font $this->fontatr>Please check your settings, if you
are not able to get it working send an email to your host!<br />This is the
error message returned by MySql: [I]" . mysql_errno() . ": " . mysql_error() .
"[/I]</div>";
exit();
}
$connection = @mysql_select_db($databname, $sql_link);
if ($connection === false) {
echo "<div align=\"center\"><font $this->fontatr>[B]Error
accessing the database: $databname![/B]</font>[NUM][LI]<font $this->fontatr>Are
you sure you entered the correct database name and the database
exists?</font>[LI]<font $this->fontatr>Are you sure that you have permission to
access this database?[/NUM]<font $this->fontatr>Please check your settings, if
you are not able to get it working send an email to your host!<br />This is the
error message returned by MySql: [I]" . mysql_errno() . ": " . mysql_error() .
"[/I]</div>";
exit();
}
}

function query($input)
{
$output = @mysql_query($input);
if (empty($output)) {
if (ereg('errno: 145', mysql_errno())) {
// repair_tables();
} else {
echo "<div align=\"center\"><font $this->fontatr>[B]Error
querying the database![/B]</font>[NUM][LI]<font $this->fontatr>Check the input
for invalid characters...</font>[LI]<font $this->fontatr>Inform the NS Forums
Developer @ http://www.nswmd.com/nsforums/[/NUM]<br />This is the query NS
Forums tried to execute: $input<br />This is the error message returned by
MySql: [I]" . mysql_errno() . ": " . mysql_error() . "[/I]</div>";
}
exit();
}
$this->querynum++;
return $output;
}

function unbuffered_query($input)
{
mysql_unbuffered_query($input) or die("Error:" . mysql_error());
$this->qn++;
return;
}

function fetch_array($input, $type = MYSQL_ASSOC)
{
$output = @mysql_fetch_array($input, $type);
return $output;
}

function num_rows($query)
{
$output = @mysql_num_rows($query);
if ($output === false) {
$output = 0;
}
return $output;
}

function result($query, $row = 0)
{
$output = @mysql_result($query, $row);
return $output;
}

function insert_id()
{
$output = @mysql_insert_id();
return $output;
}

function free_result($info)
{
$output = @mysql_free_result($info);
return $output;
}
}

?>
AddThis Social Bookmark Button