dcsimg
A Flash Developer Resource Site

Results 1 to 12 of 12

Thread: Load specific info from mysql database

  1. #1
    Member
    Join Date
    May 2006
    Posts
    70

    Load specific info from mysql database

    I have an application with 5 checkboxes, and when you hit submit, it records whether they are checked into a database. I am also able to pull all the info out of the database, but I'm having trouble pulling out the specific data I would like.

    For example, how would I write the php so it pulls out specific data such as, all the checkboxes from row #1. Or maybe all the checkboxes depending on another field such as a name.

    Thanks for any help!

  2. #2
    Member
    Join Date
    May 2006
    Posts
    70
    Ok, so I have this working kind of the way I want. I have a php file that is pulling the correct info. Here is the code:

    <?php
    $connect = mysql_connect("db", "name", "pass");
    mysql_select_db("db", $connect);
    $result = mysql_query("SELECT * FROM intro WHERE name='frank'");

    while($row = mysql_fetch_array($result))
    {

    echo "checkbox1"." ".$row['checkbox1'];
    echo "<br />";
    echo "checkbox2"." ".$row['checkbox2'];
    echo "<br />";
    echo "checkbox3"." ".$row['checkbox3'];
    echo "<br />";
    echo "checkbox4"." ".$row['checkbox4'];
    echo "<br />";
    echo "checkbox5"." ".$row['checkbox5'];
    }
    ?>

    So it pulls all the checkbox info from a user named "frank". Now how would I change it so "frank" is a variable that I am passing from flash? For instance, if someone enters there name as "Mike" in the application. How would I pull all the checkbox info for Mike?

    Thanks!

  3. #3
    Member
    Join Date
    May 2006
    Posts
    70
    I'm so close! If anyone can help me figure out this last part I would appreciate it so much!

    My question is how do I change my code so that this part of the php:
    WHERE name='frank'

    ...is pulling the "name" from flash. So let's say a user enters their name in flash, how do I make it so the php uses the name they entered, so it pulls out the correct results?

    Ok, so here is my php code:

    Code:
    <?php
    $connect = mysql_connect(dblocation", "db", "pass");
            mysql_select_db("db", $connect);
          $result = mysql_query("SELECT * FROM intro WHERE name='frank'");
    
    while($row = mysql_fetch_array($result))
      {
    	  
    $returnVars = array();
    $returnVars['checkbox1'] =$row['checkbox1'];
    $returnString = http_build_query($returnVars);
    
      }
    echo $returnString;
    
    ?>


    And here is my actionscript:

    Code:
    var request:URLRequest = new URLRequest("pull10.php");
    request.method = URLRequestMethod.GET;
    
    var loader:URLLoader = new URLLoader();
    loader.dataFormat = URLLoaderDataFormat.VARIABLES;
    loader.addEventListener(Event.COMPLETE, completeHandler);
    loader.load(request);
    
    function completeHandler(evt:Event) {
    
      var mycheckbox = evt.target.data.checkbox1;
    
    textfield1.text = mycheckbox;
    
    }

    Thanks for any help!

  4. #4
    Registered User
    Join Date
    Feb 2001
    Posts
    13,044
    Hi,

    basically it is like this: instead of
    Code:
    $result = mysql_query("SELECT * FROM intro WHERE name='frank'");
    You would see
    Code:
    $name = $_GET['name'];
    $result = mysql_query("SELECT * FROM intro WHERE name='$name'");
    and - of course - you would need to add the name variable to your request.

    Now, this will do for testing only, but not in real life: bad people might try to send
    crap instead of a name to kill your database.
    This code works safely if
    a) the host has configured magic_quotes on
    b) the default language setting of the database is western (US or european languages)

    Musicman

  5. #5
    Member
    Join Date
    May 2006
    Posts
    70
    Thanks musicman, that helped a lot! Now I ran into another issue. When I send the variable from flash like this, it works fine:
    variables.name="frank";

    But when I try to use the name from an input text box, and use this code it does not work:
    variables.name=myname.text;

    It gives me this error:
    Error #2101: The String passed to URLVariables.decode() must be a URL-encoded query string containing name/value pairs.

    Any ideas?

    Thanks!

  6. #6
    Senior Member
    Join Date
    Aug 2009
    Location
    Scotland & England
    Posts
    117
    variables.name=String(myname.text);

    Does that work?

  7. #7
    Senior Member
    Join Date
    Aug 2009
    Location
    Scotland & England
    Posts
    117
    Infact it could be because you are using .name which is part of the AS3 syntax. Try using variables.myName = myname.text;

  8. #8
    Member
    Join Date
    May 2006
    Posts
    70
    variables.name=String(myname.text);

    ...doesn't seem to be working...

    (I actually was using "myname", but thanks for the tip!)

  9. #9
    Senior Member
    Join Date
    Aug 2009
    Location
    Scotland & England
    Posts
    117
    Hmmm

    URLLoaderDataFormat.TEXT;

    instead of

    URLLoaderDataFormat.VARIABLES;

    ?

  10. #10
    Member
    Join Date
    May 2006
    Posts
    70
    Didn't work...

  11. #11
    Member
    Join Date
    May 2006
    Posts
    70
    Ok, so I think I have this figured out. I guess I had to set the text in the textfield to be blank, before I type a name in there:
    myname.text="";

    After I did that it started working!

    So how do I make it so that if there is no entry found under that name, then I can detect that in flash?

  12. #12
    AS3 Mod
    Join Date
    Sep 2007
    Location
    O-H-I-O
    Posts
    2,385
    PHP Code:
    <?php
    $connect 
    mysql_connect("dblocation""db""pass");
    mysql_select_db("db"$connect);

    $name $_GET['name'];
    $result mysql_query("SELECT * FROM intro WHERE name='$name'");

    if(
    mysql_num_rows($result) < 1)
    {
        
    $returnString 'false';
    }else{
        while(
    $row mysql_fetch_array($result))
        {
            
    $returnVars                    = array();
            
    $returnVars['checkbox1']    = $row['checkbox1'];
            
    $returnString                http_build_query($returnVars);
        }
    }
    echo 
    $returnString;
    ?>
    Then in your flash you would just say something like:

    PHP Code:
    if(responsevariable == 'false')
    {
    // No results logic


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center