# Hello World - Flash CS5, PHP, MySQL

**URL:** <https://forum.kirupa.com/t/hello-world-flash-cs5-php-mysql/327554>\
**Category:** programming\
**Created:** [March 9, 2012, 4:24am UTC](https://forum.kirupa.com/t/hello-world-flash-cs5-php-mysql/327554 "2012-03-09T04:24:27Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![joesafe](https://avatars.discourse-cdn.com/v4/letter/j/aeb1de/32.png) [@joesafe](https://forum.kirupa.com/u/joesafe)\
**Post date:** [March 9, 2012, 4:24am UTC](https://forum.kirupa.com/t/hello-world-flash-cs5-php-mysql/327554/1 "2012-03-09T04:24:27Z")

</div>

Hello,  
Please forgive me, I am an extreme noob. I’ve been trying to follow a Hello World tutorial to try and get my head around how to use Flash with php and Mysql.

I just can’t seem to get it to work.

Any help would be greatly apreciated. Sorry if this thread is in the wrong place, and sorry if I post my code incorrectly, as I said im completely new to this.

This project is running on Wampserver. It has a database called “helloworld” on phpMyadmin with 2 tables called “id” and “message”.

AS3 code

```auto

import FP9.flash.com.ps.php.as3.*;
var DB_loc:String = "http://localhost/php/";
hwselect();
//----------------------------------------
//----------BEGIN SELECT hw------------------
//----------------------------------------
function hwselect(){

var hw_table = "hello_world";
//--Array should be the table row names you wish to pull from
var hw_tableRow:Array = new Array();
hw_tableRow[0] = "id";
hw_tableRow[1] = "message";

//--where , like and what arrays must be the same length arrays 
//--must have at least a zero value for the array which can 
//--be blank ie where[0] = ""; 

//where to look
var hw_where:Array = new Array();
hw_where[0] = "";

/*values can be = <> > < <= >= BETWEEN LIKE IN You can put TABLE (i.e =TABLE)after any of the operators to use a table field in the what array value*/
var hw_like:Array = new Array();
hw_like[0] = "";

//What to look for
var hw_what:Array = new Array();
hw_what[0] = "";

//What to look for
var hw_functionStrings:Array = new Array();
hw_functionStrings[0] = "";

//orderBy and ASC arrays must have the same amount of items in the array.
//What to look for
var hw_orderBy:Array = new Array();
hw_orderBy[0] = "";

//What to look for
var hw_ASC:Array = new Array();
hw_ASC[0] = "";

var hw_select:SelectDB = new SelectDB(hw_table, hw_tableRow, hw_where, hw_like, hw_what, hw_orderBy, hw_ASC, hw_returnFunction, hw_functionStrings, DB_loc);
}
//--Return function
//you can seperate the values out using vars.the var you want.
//you already know the returned values because you set them with the tableRow array (i.e. vars.message)
function hw_returnFunction(vars:URLVariables, selectRows:Array, functionStrings:Array){
for(var i:Number = 0; i<vars.cantId; i++){
for(var ii:Number = 0; ii<selectRows.length; ii++){
//CHANGE test.text TO THE OBJECT(S) YOU WANT THE VARS TO BE PASSED

  test.text += vars[selectRows[ii]+""+i] + " - ";
}
}
}

```

Then it has a “db\_connect.php” file stored in localhost/php/db/

and a “securitybridge.php” file stored in localhost/php/

PHP - "db\_connect.php"

```php

<?php $conn = mysql_connect("localhost", "admin", "admin") or die(mysql_error()); mysql_select_db('helloworld', $conn) or die(mysql_error());?>

```

PHP securitybridge.php

```php

<?//---------------Due to security concerns you must have this set on the server since flash can only md5 or sha encrypt data.include("db/db_connect.php");//---------------Get Query type vars--------------------$qtype = $_POST['qtype'];if($qtype == "s"){ include("queries/selectDB.php");}else if($qtype == "u"){ include("queries/updateDB.php");}else if($qtype == "i"){ include("queries/insertDB.php");}else if($qtype == "d"){ include("queries/deleteDB.php");}exit();?>

```

There are also the following .php files located in localhost/php/queries/…

deleteDB.php

```php

<?//---------------Due to security concerns you must have this set on the server since flash can only md5 or sha encrypt data.include("db/db_connect.php");//---------------Get Query type vars--------------------$qtype = $_POST['qtype'];if($qtype == "s"){	include("queries/selectDB.php");}else if($qtype == "u"){	include("queries/updateDB.php");}else if($qtype == "i"){	include("queries/insertDB.php");}else if($qtype == "d"){	include("queries/deleteDB.php");}exit();?>

```

insertdb.php

```php

<?php//---------------Set user vars--------------------$forCount = $_POST['selectRowsLength'];$ASCCount = $_POST['ASCLength'];$tableName = $_POST['table1'];
//To run this function flash needs to pass in "fc and tn then tr* and trv*"$tableValues = "";$nextValue = "";$va = array();for ($ia=0; $ia<$forCount; $ia++){	if ($ia != 0){ $tableValues .= ",'";	}else{ $tableValues .= "'";	}	$nextValue = 'valueRows'.$ia;	$va[$ia] = $_POST[$nextValue];	$tableValues .= "$va[$ia]";	$tableValues .= "'";}
//----------------//To run this function flash needs to pass in "fc and tn then tr* and trv*"$tableRows = "";$nextTr = "";$tra = array();
for ($i=0; $i<$forCount; $i++){	if ($i != 0){ $tableRows .= ", ";	}	$nextTr = 'selectRows'.$i;	$tra[$i] = $_POST[$nextTr];	$tableRows .= "$tra[$i]";}//---------------End set user vars----------------//------------------------------------------------
//-------------add user function------------------	mysql_query("INSERT INTO $tableName($tableRows) VALUES($tableValues)");	// --start output string with number of entries--	echo "insertAction=Complete";?>

```

selectDB.php

```php

<?php//---------------Set user vars--------------------$forCount = $_POST['selectRowsLength'];$whereCount = $_POST['whereLength'];$ASCCount = $_POST['ASCLength'];$tableName = $_POST['table1'];//$ASC = $_POST['ASC'];//$orderBy = $_POST['orderBy'];$ASCTr = "";$orderByTr = "";$tableOrderByASC = "";$ASC = array();$orderBy = array();if($_POST['ASC0'] != "" && $_POST['orderBy0'] != ""){for ($iii=0; $iii<$ASCCount; $iii++){	if ($iii != 0){ $tableOrderByASC .= ", ";	}else{ $tableOrderByASC .= "ORDER BY ";	}	$ASCTr = 'ASC'.$iii;	$ASC[$iii] = $_POST[$ASCTr];	$orderByTr = 'orderBy'.$iii;	$orderBy[$iii] = $_POST[$orderByTr];	$tableASC = "$ASC[$iii]";	$tableOrderBy = "$orderBy[$iii]";	$tableOrderByASC .= "$tableOrderBy";	if($ASC[$iii] == "ASC"){	$tableOrderByASC .= " ASC";	}else{	$tableOrderByASC .= " DESC";	}}}//------------//echo "cantId=23";$whereTr = "";$likeTr = "";$whatTr = "";$tableWhere_What = "";$where1 = array();$like1 = array();$what1 = array();if($_POST['whereA0'] != "" && $_POST['whatA0'] != ""){for ($ii=0; $ii<$whereCount; $ii++){	if ($ii != 0){ $tableWhere_What .= " AND ";	}else{ $tableWhere_What .= "WHERE ";	}	$whereTr = 'whereA'.$ii;	$where1[$ii] = $_POST[$whereTr];	$likeTr = 'likeA'.$ii;	$like1[$ii] = $_POST[$likeTr];	$whatTr = 'whatA'.$ii;	$what1[$ii] = $_POST[$whatTr];	$tableWhere = "$where1[$ii]";	$tableWhere1 = "$what1[$ii]";	$tableWhere_What .= "$tableWhere";	if($like1[$ii] == "LIKE"){	$tableWhere_What .= " LIKE '%";	$tableWhere_What .= "$tableWhere1";	$tableWhere_What .= "%'";	}else if($like1[$ii] == "="){	$tableWhere_What .= " = '";	$tableWhere_What .= "$tableWhere1";	$tableWhere_What .= "'";	}else if($like1[$ii] == "<>"){	$tableWhere_What .= " <> '";	$tableWhere_What .= "$tableWhere1";	$tableWhere_What .= "'";	}else if($like1[$ii] == ">"){	$tableWhere_What .= " > '";	$tableWhere_What .= "$tableWhere1";	$tableWhere_What .= "'";	}else if($like1[$ii] == "<"){	$tableWhere_What .= " < '";	$tableWhere_What .= "$tableWhere1";	$tableWhere_What .= "'";	}else if($like1[$ii] == ">="){	$tableWhere_What .= " >= '";	$tableWhere_What .= "$tableWhere1";	$tableWhere_What .= "'";	}else if($like1[$ii] == "<="){	$tableWhere_What .= " <= '";	$tableWhere_What .= "$tableWhere1";	$tableWhere_What .= "'";	}else if($like1[$ii] == "BETWEEN"){	$tableWhere_What .= " BETWEEN ";	$tableWhere_What .= "$tableWhere1";	}else if($like1[$ii] == "IN"){	$tableWhere_What .= " IN (";	$tableWhere_What .= "$tableWhere1";	$tableWhere_What .= ")";	}else if($like1[$ii] == "=TABLE"){	$tableWhere_What .= " = ";	$tableWhere_What .= "$tableWhere1";	}else if($like1[$ii] == "TABLE"){	$tableWhere_What .= " = ";	$tableWhere_What .= "$tableWhere1";	}else if($like1[$ii] == "<>TABLE"){	$tableWhere_What .= " <> ";	$tableWhere_What .= "$tableWhere1";	}else if($like1[$ii] == "LIKETABLE"){	$tableWhere_What .= " LIKE ";	$tableWhere_What .= "$tableWhere1";	}else if($like1[$ii] == ">TABLE"){	$tableWhere_What .= " > ";	$tableWhere_What .= "$tableWhere1";	}else if($like1[$ii] == "<TABLE"){	$tableWhere_What .= " < ";	$tableWhere_What .= "$tableWhere1";	$tableWhere_What .= "";	}else if($like1[$ii] == ">=TABLE"){	$tableWhere_What .= " >= ";	$tableWhere_What .= "$tableWhere1";	$tableWhere_What .= "";	}else if($like1[$ii] == "<=TABLE"){	$tableWhere_What .= " <= ";	$tableWhere_What .= "$tableWhere1";	$tableWhere_What .= "";	}else if($like1[$ii] == "BETWEENTABLE"){	$tableWhere_What .= " BETWEEN ";	$tableWhere_What .= "$tableWhere1";	}else if($like1[$ii] == "INTABLE"){	$tableWhere_What .= " IN (";	$tableWhere_What .= "$tableWhere1";	$tableWhere_What .= ")";	}else{	$tableWhere_What .= " = '";	$tableWhere_What .= "$tableWhere1";	$tableWhere_What .= "'";	}}}//----------------//To run this function flash needs to pass in "fc and tn then tr* and trv*"$tableRows = "";$nextTr = "";$tra = array();
for ($i=0; $i<$forCount; $i++){	if ($i != 0){ $tableRows .= ", ";	}	$nextTr = 'selectRows'.$i;	$tra[$i] = $_POST[$nextTr];	$tableRows .= "$tra[$i]";}//---------------End set user vars----------------//------------------------------------------------
//-------------add user function------------------	$result = mysql_query("SELECT $tableRows FROM $tableName $tableWhere_What $tableOrderByASC");	// --start output string with number of entries--	$cant = 0; while($row=mysql_fetch_array($result)){ for ($i=0; $i<$forCount; $i++){ //$traSplit = split(".",""); $myTra = $tra[$i]; if (preg_match("/[.]/", $myTra)) { list($M21, $M22) = split('[.]', $myTra); $myTra = $M22; } echo "$myTra"; echo "$cant"; echo "="; echo "$row[$myTra]"; echo "&"; } $cant++; }	echo "cantId=$cant";?>

```

updateDB.php

```php

<?php//---------------Set user vars--------------------$forCount = $_POST['selectRowsLength'];$whereCount = $_POST['whereLength'];$ASCCount = $_POST['ASCLength'];$tableName = $_POST['table1'];//$ASC = $_POST['ASC'];//$orderBy = $_POST['orderBy'];$ASCTr = "";$orderByTr = "";$tableOrderByASC = "";$ASC = array();$orderBy = array();if($_POST['ASC0'] != "" && $_POST['orderBy0'] != ""){for ($iii=0; $iii<$ASCCount; $iii++){	if ($iii != 0){ $tableOrderByASC .= ", ";	}else{ $tableOrderByASC .= "ORDER BY ";	}	$ASCTr = 'ASC'.$iii;	$ASC[$iii] = $_POST[$ASCTr];	$orderByTr = 'orderBy'.$iii;	$orderBy[$iii] = $_POST[$orderByTr];	$tableASC = "$ASC[$iii]";	$tableOrderBy = "$orderBy[$iii]";	$tableOrderByASC .= "$tableOrderBy";	if($ASC[$iii] == "ASC"){	$tableOrderByASC .= " ASC";	}else{	$tableOrderByASC .= " DESC";	}}}//------------//echo "cantId=23";$whereTr = "";$likeTr = "";$whatTr = "";$tableWhere_What = "";$where1 = array();$like1 = array();$what1 = array();if($_POST['whereA0'] != "" && $_POST['whatA0'] != ""){for ($ii=0; $ii<$whereCount; $ii++){	if ($ii != 0){ $tableWhere_What .= " AND ";	}else{ $tableWhere_What .= "WHERE ";	}	$whereTr = 'whereA'.$ii;	$where1[$ii] = $_POST[$whereTr];	$likeTr = 'likeA'.$ii;	$like1[$ii] = $_POST[$likeTr];	$whatTr = 'whatA'.$ii;	$what1[$ii] = $_POST[$whatTr];	$tableWhere = "$where1[$ii]";	$tableWhere1 = "$what1[$ii]";	$tableWhere_What .= "$tableWhere";	if($like1[$ii] == "LIKE"){	$tableWhere_What .= " LIKE '%";	$tableWhere_What .= "$tableWhere1";	$tableWhere_What .= "%'";	}else if($like1[$ii] == "="){	$tableWhere_What .= " = '";	$tableWhere_What .= "$tableWhere1";	$tableWhere_What .= "'";	}else if($like1[$ii] == "<>"){	$tableWhere_What .= " <> '";	$tableWhere_What .= "$tableWhere1";	$tableWhere_What .= "'";	}else if($like1[$ii] == ">"){	$tableWhere_What .= " > '";	$tableWhere_What .= "$tableWhere1";	$tableWhere_What .= "'";	}else if($like1[$ii] == "<"){	$tableWhere_What .= " < '";	$tableWhere_What .= "$tableWhere1";	$tableWhere_What .= "'";	}else if($like1[$ii] == ">="){	$tableWhere_What .= " >= '";	$tableWhere_What .= "$tableWhere1";	$tableWhere_What .= "'";	}else if($like1[$ii] == "<="){	$tableWhere_What .= " <= '";	$tableWhere_What .= "$tableWhere1";	$tableWhere_What .= "'";	}else if($like1[$ii] == "BETWEEN"){	$tableWhere_What .= " BETWEEN ";	$tableWhere_What .= "$tableWhere1";	}else if($like1[$ii] == "IN"){	$tableWhere_What .= " IN (";	$tableWhere_What .= "$tableWhere1";	$tableWhere_What .= ")";	}else if($like1[$ii] == "=TABLE"){	$tableWhere_What .= " = ";	$tableWhere_What .= "$tableWhere1";	}else if($like1[$ii] == "TABLE"){	$tableWhere_What .= " = ";	$tableWhere_What .= "$tableWhere1";	}else if($like1[$ii] == "<>TABLE"){	$tableWhere_What .= " <> ";	$tableWhere_What .= "$tableWhere1";	}else if($like1[$ii] == "LIKETABLE"){	$tableWhere_What .= " LIKE ";	$tableWhere_What .= "$tableWhere1";	}else if($like1[$ii] == ">TABLE"){	$tableWhere_What .= " > ";	$tableWhere_What .= "$tableWhere1";	}else if($like1[$ii] == "<TABLE"){	$tableWhere_What .= " < ";	$tableWhere_What .= "$tableWhere1";	$tableWhere_What .= "";	}else if($like1[$ii] == ">=TABLE"){	$tableWhere_What .= " >= ";	$tableWhere_What .= "$tableWhere1";	$tableWhere_What .= "";	}else if($like1[$ii] == "<=TABLE"){	$tableWhere_What .= " <= ";	$tableWhere_What .= "$tableWhere1";	$tableWhere_What .= "";	}else if($like1[$ii] == "BETWEENTABLE"){	$tableWhere_What .= " BETWEEN ";	$tableWhere_What .= "$tableWhere1";	}else if($like1[$ii] == "INTABLE"){	$tableWhere_What .= " IN (";	$tableWhere_What .= "$tableWhere1";	$tableWhere_What .= ")";	}else{	$tableWhere_What .= " = '";	$tableWhere_What .= "$tableWhere1";	$tableWhere_What .= "'";	}}}//----------------//To run this function flash needs to pass in "fc and tn then tr* and trv*"$tableRows = "";$nextTr = "";$tra = array();$tableValues = "";$nextValue = "";$va = array();for ($ia=0; $ia<$forCount; $ia++){	if ($ia != 0){ $tableValues .= ",";	}else{	}	$nextTr = 'selectRows'.$ia;	$tra[$ia] = $_POST[$nextTr];	$tableValues .= "$tra[$ia]";	$tableValues .= "='";	$nextValue = 'valueRows'.$ia;	$va[$ia] = $_POST[$nextValue];	$tableValues .= "$va[$ia]";	$tableValues .= "'";}//---------------End set user vars----------------//------------------------------------------------
//-------------add user function------------------	$result = mysql_query("UPDATE $tableName SET $tableValues $tableWhere_What");	// --start output string with number of entries--	$cant = 0; echo "updateAction=Complete";?>

```

The code is supposed to populate a text box (test.text) in Flash with the data from mysql, but i just get a blank screen.

The flash file only has warnings which are mentioned in the video as being unimportant.

If asking help of this kind is bad form, then I apologise in advance of any upset.

Thanks for any help.
