Search SQL DataBase and Display Results

  • dferraro40
  • Beginner
  • Beginner
  • dferraro40
  • Posts: 52
  • Loc: Massachusetts

Post 3+ Months Ago

I have an SQL database that i would like have a simple search button then have it display the results in flash.
Does anyone know how to do that, or what the best approach would be?
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

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

Post 3+ Months Ago

flash cant interact directly with any DB , u should use a man in the middle , something like PHP ASP to send variables and receive them ...

read more ...

http://www.flash-db.com/
http://www.webmonkey.com/webmonkey/prog ... rial2.html
http://www.kirupa.com/developer/actions ... _mysql.htm
http://www.gotoandlearn.com
  • dferraro40
  • Beginner
  • Beginner
  • dferraro40
  • Posts: 52
  • Loc: Massachusetts

Post 3+ Months Ago

Thanks for the links. I have been working with using PHP to talk to the database and then build some XML that flash can read.(used the tutorial from gotoandlearn.com. Anyways this is what i have.


PHP Code: [ Select ]
 
<?php
 
 
 
 
 
$DBhost = "mysql";   // Database Server
 
   $DBuser = "*******";            // Database User
 
   $DBpass = "********";            // Database Pass
 
   $DBName = "warrents";            // Database Name
 
   $table = "peope";             // Database Table
 
 
 
 
 
$user= $name;
 
 
 
 
 
 
 
// Connect to mySQL Server
 
   $DBConn = mysql_connect($DBhost,$DBuser,$DBpass) or die("Error in GuestBook Application: " . mysql_error());
 
   // Select mySQL Database
 
   mysql_select_db($DBName, $DBConn) or die("Error in GuestBook Application: " . mysql_error());
 
 
 
// The SQL query.
 
$query = "SELECT * FROM $table WHERE last ='$user'" ;
 
$result = mysql_query($query);
 
 
 
 
 
 
 
echo "<?xml version=\"1.0\"?>\n";
 
echo "<peope>\n";
 
 
 
while($line = mysql_fetch_assoc($result)) {
 
   echo "<item> ". $line["last"] . "  ". $line["first"] . "             ". $line["dob"] . "               ". $line["charge"] . "</item>\n";
 
   
 
   
 
     
 
}
 
 
 
echo "</peope>\n";
 
 
 
mysql_close($link);
 
 
 
?>
 
 
  1.  
  2. <?php
  3.  
  4.  
  5.  
  6.  
  7.  
  8. $DBhost = "mysql";   // Database Server
  9.  
  10.    $DBuser = "*******";            // Database User
  11.  
  12.    $DBpass = "********";            // Database Pass
  13.  
  14.    $DBName = "warrents";            // Database Name
  15.  
  16.    $table = "peope";             // Database Table
  17.  
  18.  
  19.  
  20.  
  21.  
  22. $user= $name;
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30. // Connect to mySQL Server
  31.  
  32.    $DBConn = mysql_connect($DBhost,$DBuser,$DBpass) or die("Error in GuestBook Application: " . mysql_error());
  33.  
  34.    // Select mySQL Database
  35.  
  36.    mysql_select_db($DBName, $DBConn) or die("Error in GuestBook Application: " . mysql_error());
  37.  
  38.  
  39.  
  40. // The SQL query.
  41.  
  42. $query = "SELECT * FROM $table WHERE last ='$user'" ;
  43.  
  44. $result = mysql_query($query);
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52. echo "<?xml version=\"1.0\"?>\n";
  53.  
  54. echo "<peope>\n";
  55.  
  56.  
  57.  
  58. while($line = mysql_fetch_assoc($result)) {
  59.  
  60.    echo "<item> ". $line["last"] . "  ". $line["first"] . "             ". $line["dob"] . "               ". $line["charge"] . "</item>\n";
  61.  
  62.    
  63.  
  64.    
  65.  
  66.      
  67.  
  68. }
  69.  
  70.  
  71.  
  72. echo "</peope>\n";
  73.  
  74.  
  75.  
  76. mysql_close($link);
  77.  
  78.  
  79.  
  80. ?>
  81.  
  82.  


and the flash code for my search button
Code: [ Select ]
on (release) {
    
var my_vars = new LoadVars();
//Get the text from Input Text
my_vars.name=name.text;

//Send input (my_vars) to PHP and assign result back to my_vars
my_vars.sendAndLoad("search.php",my_vars,"POST");





var theXML:XML = new XML();
theXML.ignoreWhite = true;

theXML.onLoad = function() {
    var nodes = this.firstChild.childNodes;
        for(i=0;i<nodes.length;i++) {
        theList.addItem(nodes[i].firstChild.nodeValue,i);
    }
}

theXML.load("search.php");

}

    
  1. on (release) {
  2.     
  3. var my_vars = new LoadVars();
  4. //Get the text from Input Text
  5. my_vars.name=name.text;
  6. //Send input (my_vars) to PHP and assign result back to my_vars
  7. my_vars.sendAndLoad("search.php",my_vars,"POST");
  8. var theXML:XML = new XML();
  9. theXML.ignoreWhite = true;
  10. theXML.onLoad = function() {
  11.     var nodes = this.firstChild.childNodes;
  12.         for(i=0;i<nodes.length;i++) {
  13.         theList.addItem(nodes[i].firstChild.nodeValue,i);
  14.     }
  15. }
  16. theXML.load("search.php");
  17. }
  18.     


The problem is that when i put a name in the search box it displays "undefined".
If i change the name variable to a string variable like "ADAMEN"(someones last name) and i dont try and get
the variable from Flash then the query works and displays the results. I'm not sure why i cant get flash to send the variable, it seems like it is something simple but i have tryed all sorts of things trying to get this to work. I hope you can see where i am going wrong.
  • classified
  • Expert
  • Expert
  • User avatar
  • Posts: 540
  • Loc: Bahrain

Post 3+ Months Ago

ok im out of time here...and im getting confused HEH !

i think its better that u make PHP creates XML on server then make flash loads it up

and on php better do this
PHP Code: [ Select ]
$user=  $_POST['name'];



U will need 2 loadvars one to send and one to receive ...


Code: [ Select ]
var my_vars = new LoadVars();
var my_rcv_vars = new LoadVars();

//Get the text from Input Text

my_vars.name=name.text;

//Send input (my_vars) to PHP and assign result back to my_rcv-vars

my_vars.sendAndLoad("search.php",my_rcv_vars ,"POST");
  1. var my_vars = new LoadVars();
  2. var my_rcv_vars = new LoadVars();
  3. //Get the text from Input Text
  4. my_vars.name=name.text;
  5. //Send input (my_vars) to PHP and assign result back to my_rcv-vars
  6. my_vars.sendAndLoad("search.php",my_rcv_vars ,"POST");


better make a variable that will hold the name of the created XML

then use onLoad method ...




Code: [ Select ]
my_rcv_vars.onLoad = function() {

     //create the function that will load the created XML
}
  1. my_rcv_vars.onLoad = function() {
  2.      //create the function that will load the created XML
  3. }


[/code]
  • dferraro40
  • Beginner
  • Beginner
  • dferraro40
  • Posts: 52
  • Loc: Massachusetts

Post 3+ Months Ago

I changed
Code: [ Select ]
$user= $name;

to...
Code: [ Select ]
$user=  $_POST['name']; 

and i am still getting the "undefined".
Is there a way i can tell if the varible is being sent? I used trace(my_vars); and in the output pannel it says name=whateverisinthenametxtbox, so i think that means that the var "name" is being sent , but is there a way i can see if the php script is getting it?
I put
PHP Code: [ Select ]
 
$user=    $_POST['name'];  
 
$status = $user;
 
echo $user;
 
 
  1.  
  2. $user=    $_POST['name'];  
  3.  
  4. $status = $user;
  5.  
  6. echo $user;
  7.  
  8.  

And my status box says "underfined"
  • Nucleo
  • SausagePorkPie
  • Mastermind
  • User avatar
  • Posts: 2297
  • Loc: UK - England

Post 3+ Months Ago

Hi

An awsome php script I came accross, basically use loadVars and send your data to this php script

PHP Code: [ Select ]
 
<? php
 
foreach ($_POST as $key=>$value) {
 
$received .= "$key = $value\r\n";
 
}
 
 
 
$printout = fopen('variables.txt', 'w');
 
fwrite($printout, $received);
 
fclose($printout);
 
?>
 
 
  1.  
  2. <? php
  3.  
  4. foreach ($_POST as $key=>$value) {
  5.  
  6. $received .= "$key = $value\r\n";
  7.  
  8. }
  9.  
  10.  
  11.  
  12. $printout = fopen('variables.txt', 'w');
  13.  
  14. fwrite($printout, $received);
  15.  
  16. fclose($printout);
  17.  
  18. ?>
  19.  
  20.  


This will make a text file of all the POST ' ed variables, great for debugging.
  • dferraro40
  • Beginner
  • Beginner
  • dferraro40
  • Posts: 52
  • Loc: Massachusetts

Post 3+ Months Ago

I'm not sure what the deal is, i have used Flash to pass variables before and never had a proplem, i have read a ton of documents that show how send variables and it all seems pretty strait forward. I am not trying to reinvent the wheel. There has to be something small that i am overlooking. For some reason i can not get the variable into the PHP file :(
  • classified
  • Expert
  • Expert
  • User avatar
  • Posts: 540
  • Loc: Bahrain

Post 3+ Months Ago

dferraro40 wrote:
I'm not sure what the deal is, i have used Flash to pass variables before and never had a proplem, i have read a ton of documents that show how send variables and it all seems pretty strait forward. I am not trying to reinvent the wheel. There has to be something small that i am overlooking. For some reason i can not get the variable into the PHP file :(


chill bro ... U must have forgotten something somewhere , a typo prolly ...

send me your files let me have a look @ them ...
  • IceCold
  • Guru
  • Guru
  • User avatar
  • Posts: 1254
  • Loc: Ro

Post 3+ Months Ago

usually rewriting it will solve the problem :P
  • dferraro40
  • Beginner
  • Beginner
  • dferraro40
  • Posts: 52
  • Loc: Massachusetts

Post 3+ Months Ago

You can find my files at http://www.davidferraro.net/test/
Thank you for helping me with this, i have been pulling my hair out, lol.
  • classified
  • Expert
  • Expert
  • User avatar
  • Posts: 540
  • Loc: Bahrain

Post 3+ Months Ago

just before i start working on your code , and before i start pulling my hair out " lawl " ..

did u actually include the full path of the webserver .. ?
Code: [ Select ]
my_vars.sendAndLoad("HTTP://WWW.XYZ.COM/search.php",my_rcv_vars ,"POST");


u got a typo on people DB name
Quote:
" peope "
...

now im gonna work on it :D
  • dferraro40
  • Beginner
  • Beginner
  • dferraro40
  • Posts: 52
  • Loc: Massachusetts

Post 3+ Months Ago

yes i tried it both ways, I belive the path in the .fla is the full path.
"peope" is the name of the table, i meant to put "people" but i just kept it at "peope", lol, i was going to change the table name to "people" but i havent got around to it yet, i was just trying to get it to work.
The connection the the db and table works fine, i tested it, its just the variable "name" being sent from flash is not
getting there. If i change the variable to someones name(like "Edwards") in the search.php is will work, but if i make it so it gets the varable from flash i keep getting "undefined"
  • classified
  • Expert
  • Expert
  • User avatar
  • Posts: 540
  • Loc: Bahrain

Post 3+ Months Ago

could'nt do it your way realy , but done it my way..
the PHP will create the XML file on the server then sends the file name back to flash , flash then loads the XML and adds the values to the list .

few errors in PHP
here is the new codes ...




PHP Code: [ Select ]
<?php  
 
 
 
 
 
$user=$_POST['name'];
 
$XMLFILE =  $user ."." ."xml";
 
//create XML file on Server
 
touch($XMLFILE);
 
 
 
//$user = "ADAMEN";
 
 
 
$DBhost  =  "localhost";      //  Database  Server
 
      $DBuser  =  "root";                        //  Database  User
 
      $DBpass  =  "";                        //  Database  Pass
 
      $DBName  =  "warrents";                        //  Database  Name
 
      $table  =  "people";                          //  Database  Table
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
//  Connect  to  mySQL  Server
 
$DBConn  =  mysql_connect($DBhost,$DBuser,$DBpass)  or  die("Error  in  GuestBook  Application:  "  .  mysql_error());
 
      //  Select  mySQL  Database
 
 mysql_select_db($DBName,  $DBConn)  or  die("Error  in  GuestBook  Application:  "  .  mysql_error());
 
 
 
//  The  SQL  query.  
 
$query  =  "SELECT  *  FROM  $table  WHERE  last  ='$user'"  ;  
 
$result  =  mysql_query($query);  
 
 
 
 
 
if($result){
 
   
 
   
 
   
 
   //echo"<item>  moodz";
 
$Text2Write = "<?xml  version=\"1.0\"?>\n
 
<peope>\n";
 
   
 
 
 
   
 
 while($line  =  mysql_fetch_assoc($result))  {
 
    $Text2Write .=  "<item>  ".  $line["last"]  . " ".  $line["first"]  .  "</item>\n";
 
       
 
       
 
               
 
}
 
 
 
$Text2Write.="</peope>\n";
 
}else{
 
   echo " Whateva";
 
}
 
$fp = fopen($XMLFILE,"w");
 
fwrite($fp,"$Text2Write");
 
fclose($fp);
 
 
 
echo"toload=$XMLFILE";
 
 
 
//mysql_close($link);
 
 
 
?>
  1. <?php  
  2.  
  3.  
  4.  
  5.  
  6.  
  7. $user=$_POST['name'];
  8.  
  9. $XMLFILE =  $user ."." ."xml";
  10.  
  11. //create XML file on Server
  12.  
  13. touch($XMLFILE);
  14.  
  15.  
  16.  
  17. //$user = "ADAMEN";
  18.  
  19.  
  20.  
  21. $DBhost  =  "localhost";      //  Database  Server
  22.  
  23.       $DBuser  =  "root";                        //  Database  User
  24.  
  25.       $DBpass  =  "";                        //  Database  Pass
  26.  
  27.       $DBName  =  "warrents";                        //  Database  Name
  28.  
  29.       $table  =  "people";                          //  Database  Table
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45. //  Connect  to  mySQL  Server
  46.  
  47. $DBConn  =  mysql_connect($DBhost,$DBuser,$DBpass)  or  die("Error  in  GuestBook  Application:  "  .  mysql_error());
  48.  
  49.       //  Select  mySQL  Database
  50.  
  51.  mysql_select_db($DBName,  $DBConn)  or  die("Error  in  GuestBook  Application:  "  .  mysql_error());
  52.  
  53.  
  54.  
  55. //  The  SQL  query.  
  56.  
  57. $query  =  "SELECT  *  FROM  $table  WHERE  last  ='$user'"  ;  
  58.  
  59. $result  =  mysql_query($query);  
  60.  
  61.  
  62.  
  63.  
  64.  
  65. if($result){
  66.  
  67.    
  68.  
  69.    
  70.  
  71.    
  72.  
  73.    //echo"<item>  moodz";
  74.  
  75. $Text2Write = "<?xml  version=\"1.0\"?>\n
  76.  
  77. <peope>\n";
  78.  
  79.    
  80.  
  81.  
  82.  
  83.    
  84.  
  85.  while($line  =  mysql_fetch_assoc($result))  {
  86.  
  87.     $Text2Write .=  "<item>  ".  $line["last"]  . " ".  $line["first"]  .  "</item>\n";
  88.  
  89.        
  90.  
  91.        
  92.  
  93.                
  94.  
  95. }
  96.  
  97.  
  98.  
  99. $Text2Write.="</peope>\n";
  100.  
  101. }else{
  102.  
  103.    echo " Whateva";
  104.  
  105. }
  106.  
  107. $fp = fopen($XMLFILE,"w");
  108.  
  109. fwrite($fp,"$Text2Write");
  110.  
  111. fclose($fp);
  112.  
  113.  
  114.  
  115. echo"toload=$XMLFILE";
  116.  
  117.  
  118.  
  119. //mysql_close($link);
  120.  
  121.  
  122.  
  123. ?>



flash


Code: [ Select ]
on(release){
    //loadVariablesNum (search, 0, "POST");
answer = "Please Wait....";
var my_vars = new LoadVars();
var my_rcv_vars = new LoadVars();

//Get the text from Input Text
my_vars.name=name.text;

//Send input (my_vars) to PHP and assign result back to my_rcv-vars

my_vars.sendAndLoad("http://localhost:8080/search/search.php",my_rcv_vars ,"POST");
trace(my_vars);


//When recieving the return from the PHP file load the XML    
my_rcv_vars.onLoad = function() {
    trace('loaded');
    //traces the XML file that should be loaded ...
    trace(my_rcv_vars.toload );
    var theXML:XML = new XML();
    theXML.ignoreWhite = true;
    //trace(theXML);

//trace(nodes);
    theXML.onLoad = function() {
        var nodes = this.firstChild.childNodes;
     for(i=0;i<nodes.length;i++) {
         theList.addItem(nodes[i].firstChild.nodeValue,i);
    
     }
    }

    
theXML.load("http://localhost:8080/search/" + my_rcv_vars.toload );
}
//onrelease Ending
}
  1. on(release){
  2.     //loadVariablesNum (search, 0, "POST");
  3. answer = "Please Wait....";
  4. var my_vars = new LoadVars();
  5. var my_rcv_vars = new LoadVars();
  6. //Get the text from Input Text
  7. my_vars.name=name.text;
  8. //Send input (my_vars) to PHP and assign result back to my_rcv-vars
  9. my_vars.sendAndLoad("http://localhost:8080/search/search.php",my_rcv_vars ,"POST");
  10. trace(my_vars);
  11. //When recieving the return from the PHP file load the XML    
  12. my_rcv_vars.onLoad = function() {
  13.     trace('loaded');
  14.     //traces the XML file that should be loaded ...
  15.     trace(my_rcv_vars.toload );
  16.     var theXML:XML = new XML();
  17.     theXML.ignoreWhite = true;
  18.     //trace(theXML);
  19. //trace(nodes);
  20.     theXML.onLoad = function() {
  21.         var nodes = this.firstChild.childNodes;
  22.      for(i=0;i<nodes.length;i++) {
  23.          theList.addItem(nodes[i].firstChild.nodeValue,i);
  24.     
  25.      }
  26.     }
  27.     
  28. theXML.load("http://localhost:8080/search/" + my_rcv_vars.toload );
  29. }
  30. //onrelease Ending
  31. }


i tried it it worked fine with me

in the table i only created 2 fields that is first and last ... u can add more if you wish .


Now remember you might what to consider making more functions within PHP and organize it ,
suppose that someone sends the same query so it checks if the file exists within the server ( opens it and appends new data , or just delets it and create a new XML ... etc ...


Files can be found @ http://www.zainals.com/xperments/searchFlaMysql.zip

good luck.
  • dferraro40
  • Beginner
  • Beginner
  • dferraro40
  • Posts: 52
  • Loc: Massachusetts

Post 3+ Months Ago

i am useing Flash MX i get a unexpected file format when i try to open it.
  • classified
  • Expert
  • Expert
  • User avatar
  • Posts: 540
  • Loc: Bahrain

Post 3+ Months Ago

oooooooo ma bad :oops:

download it again , saved it as MX .

http://www.zainals.com/xperments/searchFlaMysql.zip
  • dferraro40
  • Beginner
  • Beginner
  • dferraro40
  • Posts: 52
  • Loc: Massachusetts

Post 3+ Months Ago

you are badass! When i grow up i want to be just like you!:)
Thank you sooooo much!
  • classified
  • Expert
  • Expert
  • User avatar
  • Posts: 540
  • Loc: Bahrain

Post 3+ Months Ago

dferraro40 wrote:
you are badass! When i grow up i want to be just like you!:)
Thank you sooooo much!


hahahaha been there done that ;)
glad it worked .
  • IceCold
  • Guru
  • Guru
  • User avatar
  • Posts: 1254
  • Loc: Ro

Post 3+ Months Ago

seems like you got yourself a fan :D
  • classified
  • Expert
  • Expert
  • User avatar
  • Posts: 540
  • Loc: Bahrain

Post 3+ Months Ago

IceCold wrote:
seems like you got yourself a fan :D


hushhh , lemme enjoy the glory of this moment , im now officially a badass :lol:
  • IceCold
  • Guru
  • Guru
  • User avatar
  • Posts: 1254
  • Loc: Ro

Post 3+ Months Ago

just like Samuel L. Jackson in pulp fiction: a badass mofo :D
  • sajid82
  • Born
  • Born
  • sajid82
  • Posts: 2

Post 3+ Months Ago

hi guys..
could any body tell me why i m getting this error:
Fatal error*: Call to undefined function mysql_connect() in *C:\Program Files\Apache Group\Apache2\htdocs\GuestBook.php* on line *14*.

my codes:
<?php


// Part One - Initiate a mySQL Database Connection
// Database Connectivity Variables and other Variables
$DBhost = "localhost"; // Database Server
$DBuser = "root"; // Database User
$DBpass = "q"; // Database Pass
$DBName = "flashphp"; // Database Name
$table = "guestbook"; // Database Table
$numComments = 10; // Number of Comments per page
// Connect to mySQL Server
$DBConn = mysql_connect($DBhost,$DBuser,$DBpass) or die("Error
in GuestBook Application: " . mysql_error());
// Select mySQL Database
mysql_select_db($DBName, $DBConn) or die("Error in GuestBook
Application: " . mysql_error());
?>
  • sajid82
  • Born
  • Born
  • sajid82
  • Posts: 2

Post 3+ Months Ago

does any of you guys knows how to make flash cart, first flash connect to php then take data through mysql and then give post to flash...i hope u got my point

Post Information

  • Total Posts in this topic: 22 posts
  • Users browsing this forum: No registered users and 7 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.