A Flash Developer Resource Site

Page 3 of 5 FirstFirst 12345 LastLast
Results 41 to 60 of 93

Thread: Load a movie into flash using a PHP file

  1. #41
    Product Designer keyone.it's Avatar
    Join Date
    Aug 2001
    Location
    Rome, Italy.
    Posts
    1,625
    I'm sorry but I don't get your point. You should show me the full code.

    Anyway you can't use array calls in strings. The double quotes tell PHP to swap varnames with their values, but it only works with simple variable names.

    You should use this instead:
    PHP Code:
    $addData mysql_query("INSERT INTO $tableName (" $Fields[0] . ', ' $Fields[1] . ") VALUES ($var1$var2);"); 
    Hope this helps
    Altruism does not exist. Sustainability must be made profitable.

  2. #42
    Senior Member ninjakannon's Avatar
    Join Date
    Sep 2004
    Posts
    393
    That should fix it then. It gave me an error that basicaly said that it could not find the fields with the names of my variables in the VALUES section. The array calls were confusing it, thus it thought that the values were still field names.

    Or that's what I think anyway, I'll check it out.
    Thanks
    ninjakannon

    - My Website -

  3. #43
    Senior Member ninjakannon's Avatar
    Join Date
    Sep 2004
    Posts
    393
    No, nothing's changed.
    Here's my whole code:
    PHP Code:
    <?php

    header
    ("Cache-control: no-cache");
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
    header("Cache-Control: no-store, no-cache, must-revalidate");
    header("Cache-Control: post-check=0, pre-check=0"false);
    header("Pragma: no-cache");

    $db_connect mysql_connect("localhost""myusername""mypass") or die ('I cannot connect to the database because: ' mysql_error());
    mysql_select_db("mydatabase"$db_connect) or die('error sellecting db: ' mysql_error());

    $getTotalRows mysql_query("SELECT * FROM mytable"$db_connect) or die ('I could not run this query because: ' mysql_error());
    $totalRows mysql_num_rows($getTotalRows) or die ('Could not perform function');

    $NewID $totalRows+1;

    echo 
    '$NewID = ' $NewID ' & ';

    $NewName $_POST['newusername'];
    $NewPass $_POST['newpassword'];

    echo 
    '$NewName = ' $NewName ' & ';
    echo 
    '$NewPass = ' $NewPass '... &  ------  any errors: ';

    $tableName 'mytable';
    $Field_1 'field1';
    $Field_2 'field2';
    $Field_3 'field3';
    $Field_4 'field4';
    $Field_5 'field5';
    $Field_6 'field6';

    $addData mysql_query("INSERT INTO $tableName ($Field_1$Field_2$Field_3$Field_4$Field_5$Field_6) VALUES ($NewID$NewName$NewPass, 'false', NULL, NULL)"$db_connect) or die (mysql_error());

    mysql_close($db_connect);

    ?>
    The $NewName and $NewPass variables are recieved from an swf file. This script will only write to the database if both variables are numbers. Otherwise I get an error like: Unknown column 'testuser' in 'field list'. Where 'testuser' is would be what $NewName equals, or if I change newname to a number, where $NewPass is. I get no error with $NewID because it is allready a number.
    ninjakannon

    - My Website -

  4. #44
    Senior Member ninjakannon's Avatar
    Join Date
    Sep 2004
    Posts
    393
    I've fixed my promlem!

    The error was in this line, which was:
    PHP Code:
    $addData mysql_query("INSERT INTO $tableName ($Field_1$Field_2$Field_3$Field_4$Field_5$Field_6) VALUES ($NewID$NewName$NewPass, 'false', NULL, NULL)"$db_connect) or die (mysql_error()); 
    I changed it to:
    PHP Code:
    $addData mysql_query("INSERT INTO $tableName ($Field_1$Field_2$Field_3$Field_4$Field_5$Field_6) VALUES ('$NewID', '$NewName', '$NewPass', 'false', NULL, NULL)"$db_connect) or die (mysql_error()); 
    (I put apostrophies arround the variables.)
    ninjakannon

    - My Website -

  5. #45
    Senior Member ninjakannon's Avatar
    Join Date
    Sep 2004
    Posts
    393
    I can also use array calls, just so you know. They work fine.
    ninjakannon

    - My Website -

  6. #46
    Senior Member ninjakannon's Avatar
    Join Date
    Sep 2004
    Posts
    393
    Right,

    Now another question, I can select a specific username like so:

    PHP Code:
    $Search mysql_query("SELECT * FROM $tableName WHERE '$Username' LIKE '$FindUser' LIMIT 1, 1"$db_connect); 
    So how do I find data in another field in the same record?

    Cheers,
    ninjakannon

    - My Website -

  7. #47
    Senior Member ninjakannon's Avatar
    Join Date
    Sep 2004
    Posts
    393
    Don't worry, I've solved my problem =)
    ninjakannon

    - My Website -

  8. #48
    Product Designer keyone.it's Avatar
    Join Date
    Aug 2001
    Location
    Rome, Italy.
    Posts
    1,625
    I've read all your posts.. I'm sorry, I'm can get distracted far too easily... I should have noticed the missing quotes... obviously needed to delimit strings.

    Array calls in strings are a bit of a reach, in any case it doesn't work with associative arrays.

    When retrieving data from db you have many ways of doing so, for both the sql and the php sides:

    PHP Code:
    // sql type 1
    $query "SELECT * FROM tblname WHERE foo LIKE '%searchword%'";
    // sql type 2
    $query "SELECT t.fldname1, t.fldname2 FROM tblname t WHERE foo LIKE '%searchword%'";

    $result mysql_query($query);
    // php type 1
    while($row mysql_fetch_array($result)) {
        echo 
    $row[0]; // you need to know field positions
    // php type 2
    while($row mysql_fetch_assoc($result)) {
        echo 
    $row['id']; // you need to know field names or make a loop to go through them
    // php type 3
    while($row mysql_fetch_object($result)) {
        echo 
    $row->id// you need to know field names or make a loop to go through them 
    Hope this helps.. anyway just type "mysql" in the search form in the php.net homepage!
    Altruism does not exist. Sustainability must be made profitable.

  9. #49
    Senior Member ninjakannon's Avatar
    Join Date
    Sep 2004
    Posts
    393
    I didn't realise there were so many ways to do this

    I used this to get a row:
    PHP Code:
    $Search mysql_query("SELECT field1,field2,field3,field4,field5,field6,field7 FROM $tableName WHERE field2 LIKE '$FindUser'"$db_connect) or die ('ERROR!: ' mysql_error());

    $row mysql_fetch_row($Search) or die ('Could not get row!');
    echo 
    $row[0] . "\n";
    echo 
    $row[1] . "\n";
    echo 
    $row[2] . "\n";
    echo 
    $row[3] . "\n";
    echo 
    $row[4] . "\n";
    echo 
    $row[5] . "\n";
    echo 
    $row[6]; 
    This works fine, I used php.net - as you have suggested before - to work it out.
    ninjakannon

    - My Website -

  10. #50
    Product Designer keyone.it's Avatar
    Join Date
    Aug 2001
    Location
    Rome, Italy.
    Posts
    1,625
    well, in that case you just make a loop..
    PHP Code:
    while($row mysql_fetch_row($Search)) {
        foreach(
    $row as $item) {
            echo 
    "$item\n";
        }

    Altruism does not exist. Sustainability must be made profitable.

  11. #51
    Senior Member ninjakannon's Avatar
    Join Date
    Sep 2004
    Posts
    393
    I just put the echo's on for testing really, so I saw no need to create a loop as I only need to withdraw one data item from the whole row; I was just checking that it got everything correctly.

    I use this code to retrieve any data I want about my users. The php files are run from flash and, for example, when a user logs in one of the fields is read; using this code I can find the field and verify their password. Then send the information back to flash.
    ninjakannon

    - My Website -

  12. #52
    Product Designer keyone.it's Avatar
    Join Date
    Aug 2001
    Location
    Rome, Italy.
    Posts
    1,625
    Ok, I got curious so I gave it a try: it's the simplest thing really...

    1) How it works: PHP reads the Flash movie file in binary mode, spits the right Content-Type header and echo's the Flash movie stream to the client, just as the server would do when calling the swf file directly, but this way you can place the swf file OUTSIDE of the public_html directory, so it is accessible only through the PHP script.

    2) The code:
    PHP Code:
    <?php
    $filename 
    'test.swf'//address is relative to the PHP file, but may be absolute or wrapped...
    $handle fopen($filename'rb'); // opens a reference to the file, in binary mode
    $content fread($handlefilesize($filename)); // stores the file stream into a string
    fclose($handle); // closes the reference, that is no longer necessary
    header('Content-Type: application/x-shockwave-flash'); // spits the right header
    echo $content// echo's the file stream to the client browser... and et voilÃ*!
    ?>

    3) Working sample:
    Test2.php

    Hope this helps!

    Altruism does not exist. Sustainability must be made profitable.

  13. #53
    Senior Member ninjakannon's Avatar
    Join Date
    Sep 2004
    Posts
    393
    I like that very good!

    One question: if my php file is in a directory I can specify a filepath to a file if it is in one of the child directories, for example:

    dir1 .... -> .... dir2 .... -> .... dir 3
    . || ............... ||
    . || ................ === contains file2.php
    . ||
    .. === contains file.php

    (Ignore the dots, that's just to get the spacing right (multiple spaces are changed to single spaces) - this is supposed to show files in 2 files in 3 different directories).

    I can get file.php to give a the filepath to a file in dir1, dir2 or dir3. But how can I get file2.php to give a filepath to a file in dir1? And how do I specify a filepath to a file outside the public_html directory?

    Thanks
    ninjakannon

    - My Website -

  14. #54
    Product Designer keyone.it's Avatar
    Join Date
    Aug 2001
    Location
    Rome, Italy.
    Posts
    1,625
    on unix systems, filesystem paths works in the same way as wrapped paths (an http://foo is a wrapped path).

    ./ = same directory
    ../ = parent directory
    / = root (on shared servers this is the root of your resources, which in some cases will reproduce a whole virtual machine, so an absolute path to your public_html will be "/var/www/html/")

    You can move how you like best in paths...
    "../../../../mydirectory/myfile.php" <-- this will jump up 4 directories and go down "mydirectory" to fetch "myfile.php".

    Hope this helps

    Altruism does not exist. Sustainability must be made profitable.

  15. #55
    Senior Member ninjakannon's Avatar
    Join Date
    Sep 2004
    Posts
    393
    Yep, definatly helps...

    I have had a thought; in your example you echo $content. Well, say you were to print $content... If you print a variable in a php file that was run from an swf file then it will recieve the variable. So could you send the laoded swf file back to flash in this way? Or would it just get some useless data?

    Thanks again!
    ninjakannon

    - My Website -

  16. #56
    Product Designer keyone.it's Avatar
    Join Date
    Aug 2001
    Location
    Rome, Italy.
    Posts
    1,625
    You missed me there, I'm a little confused...

    Anyway echo and print do the same thing.
    What we are doing here is just serving the swf file to the client, which may be a browser or a Flash movie loading it.

    I am making a couple tests, will be back with a little tute
    Altruism does not exist. Sustainability must be made profitable.

  17. #57
    Senior Member ninjakannon's Avatar
    Join Date
    Sep 2004
    Posts
    393
    Sorry I lost you there. What I meant was could you load a movie into flash in this way somehow? Instead of just letting it load into the php file.
    ninjakannon

    - My Website -

  18. #58
    Product Designer keyone.it's Avatar
    Join Date
    Aug 2001
    Location
    Rome, Italy.
    Posts
    1,625
    Yes, that is exacly the purpose.
    I am trying a new method, neater (still have to upload and test it).

    Anyway Flash loads the file just as any browser would do, from the server point of view.

    This means that in flash you just need to do the following:

    targetMovie.loadMovie('test.php');

    This should work perfectly, I still have to check it though, will be back to you in a moment.
    Altruism does not exist. Sustainability must be made profitable.

  19. #59
    Senior Member ninjakannon's Avatar
    Join Date
    Sep 2004
    Posts
    393
    I thought it would be that (targetMovie.loadMovie('test.php')), after rethinking what I said earlier.

    I am guessing that the swf file would be cached, but if you apply the code in the secureswf.fla file then people would not be able to play your swf file on their computer from cache or simply type the filepath into their web browser. Which is perfect!

    The only problem would be people with decompilers, and that's where obfuscators come in
    ninjakannon

    - My Website -

  20. #60
    Product Designer keyone.it's Avatar
    Join Date
    Aug 2001
    Location
    Rome, Italy.
    Posts
    1,625
    Ok, I have posted a simple framework for this..

    Remember to read the instructions, there are two important things to notice!

    Hope this helps...

    http://www.flashkit.com/board/showth...54#post3590754
    Altruism does not exist. Sustainability must be made profitable.

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