34 Replies Latest reply on Oct 26, 2009 10:10 AM by Adamcbrz

    Help with simple PHP

    Ron Colmen Level 2

      1. In mysql db, I created a field called "logo" and made it a 'blob'. Using the BROWSE button in the mysql db I uploaded a 10KB logo. Is that correct? will I be able to pull the 10KB logo from PHP?

       

       

      2. WHy isn't the image been comming in to flash? Will the code marked in red do it successfully?

       

      // $SomeVar is the ID


      $query = "SELECT * FROM dyomails WHERE identity = '$SomeVar'";
      $results = mysql_query($query);
      if($line = mysql_fetch_assoc($results))
      {
      echo $line["email"];
      echo '<img src="'.$line["logo"].'" alt="ruth" />';
      }

       

       

      3. 'ruth.jpg' is my logo name. Is my code correct in pulling it?

       

      echo '<img src="'.$line["logo"].'" alt="ruth" />';

        • 1. Re: Help with simple PHP
          Adamcbrz

          You can store images in a blob field type but most of the time I wouldn't recommend it. I am of the thought process if I have to make something act like a file then I will just keep the file.

           

          So instead of saving the image bytes to the database why don't you move the uploaded file to a specific folder and save the path to the database. Then when you request it from the database you are getting the image path to the image and not a list of bytes that you have to then convert back to an image.

           

          Here is a good tutorial to reference for file upload and storing to a directory:

          http://www.tizag.com/phpT/fileupload.php

           

          Hope this helps.

           

          -Adam

          1 person found this helpful
          • 2. Re: Help with simple PHP
            Ron Colmen Level 2

            Thanks Adam.    I think you've got experience in this.

             

            You mean just to type the path of the logo file in a field on the db?

            • 3. Re: Help with simple PHP
              Adamcbrz Level 2

              Right

               

              Thanks,

              Adam Brzozowski

              • 4. Re: Help with simple PHP
                Ron Colmen Level 2

                 

                 

                Could youplease answer my intial questions. or could you provide me with some sample script in PHP and action script?

                 

                I'd like to see some answers to my 2 & 3 rd questions too.

                • 5. Re: Help with simple PHP
                  Adamcbrz Level 2

                  ok under the assuption that your database table dyomails has field names email and logo your script should work. Also assuming your path to your image is in the same directory as your php file.

                   

                   

                  // $SomeVar is the ID

                   

                  $imagepath = "images/";


                  $query = "SELECT * FROM dyomails WHERE identity = '$SomeVar'";
                  $results = mysql_query($query);
                  if($line = mysql_fetch_assoc($results))
                  {
                  echo $line["email"];
                  echo '<img src="'.$imagepath.$line["logo"].'" alt="ruth" />';

                  // if your database field is named logo and it is outputting ruth.jpg then it should try

                  // display images/ruth.jpg for the image. I would test this with out flash before pulling

                  // in into flash.
                  }

                   

                  If after you test the php side of things you still aren't getting the image to show up in flash then its in flash. I am assuming you are setting this to a textfield and that text field has html enabled and you are setting the php response to that textfield.htmlText. If you are doing all this in flash then it is probably a problem with your path. If that is the case it might be a little more helpful to attach a stripped down version of what you are trying to accomplish.

                   

                  -Adam

                  • 6. Re: Help with simple PHP
                    Ron Colmen Level 2

                    Thanks a lot Adam!! I highly appriciate your input.

                     

                    I hope this ends my worries in getting the logo image and email displayed in my flash file. I'll check and get back.

                     

                     

                    • 7. Re: Help with simple PHP
                      Ron Colmen Level 2

                      1st Step:

                       

                      when I ran the php in the browser - I could only see the email there was no image (just a red X box). As you mentioned the image folder is in the same folder as the php.

                       

                      I don't know if this is important but in my db i've created a varchar to write the path where ruth.jpg is located. (http://www.abc.com/abc/uploads/ruth.jpg)

                       

                       

                      Also shouldn't this be

                       

                      echo '<img src="'.$imagepath.$line["logo"].'" alt="ruth" />';

                       

                      as follows. (if not what about other logo file names?)

                       

                      echo '<img src="'.$imagepath.$line["logo"].'" alt="" />';

                      • 8. Re: Help with simple PHP
                        Adamcbrz Level 2

                        ok if you are getting an red x your image can't be found so its what is it outputting?

                         

                        ok stepping though the process here is what i am assuming or understand:

                         

                        you have a database table with fields email, and logo.

                        For example i am going to use the following as my field data:

                        email: ad@am.com

                        logo: ruth.jpg

                         

                        run you query like you are doing.

                         

                        if you have the full path to your image in the database then you don't need $imagepath variable. That was more if you you just wanted the image basename in the database and then prepend the path to that image in the script. either way works. But since your image is in the same directory as the php file we wont worry about the $imagepath variable...

                         

                        echo '<img src="'.$imagepath.$line["logo"].'" alt="" />'; //you can do what you want with the alt probably add a description of the image if need be

                         

                        If you still get a red X see what the image path is being set to and if it doesn't match what you expect then adjust the path.

                         

                        If you still can't figure it out attach a sample file and I can adjust it to make it work.

                         

                        Thanks,

                        Adam

                        1 person found this helpful
                        • 9. Re: Help with simple PHP
                          Ron Colmen Level 2

                          Hello Adam. I highly appriciate your interist in helping me out. Thank you!

                           

                          I'm still having the same issue. Here I've attached a sample. Also I've attached a text document explaining how I want it operating.

                           

                          I'm having difficulties in attaching my FLA. So I changed the extention. Please rename it. (attchment = sample.fla)

                           

                          I'm using Flash 8 (AS 2)

                          Hope to hear from you soon.

                          Thanks once again.

                          • 10. Re: Help with simple PHP
                            Adamcbrz Level 2

                            Can i see your table structure/values you want to get in the database to make sure it all make since and i can give you a good anwser...can be a screenshot or a database dump whatever.

                            • 11. Re: Help with simple PHP
                              Ron Colmen Level 2

                              Here's a screenshot of the table structure.

                               

                               

                              • 12. Re: Help with simple PHP
                                Ron Colmen Level 2

                                Hello Adam. I hope everything is going fine.

                                 

                                I'm waiting impatiently to see the fla working!

                                 

                                 

                                • 13. Re: Help with simple PHP
                                  Adamcbrz Level 2

                                  Sorry for the delay.

                                   

                                  Here is what i have that worked:

                                   

                                  I created a folder at the root of my server. so the stucture of the server was...

                                  http://www.example.com/test  //contained everything

                                   

                                  in that folder i had two files

                                  test.php

                                  cw.png

                                   

                                  the that worked for me was:

                                   

                                  <?php

                                  mysql_connect("HOST", "USER", "PASSWORD");

                                  mysql_select_db("DATABASE");

                                  $SomeVar = 'fin';

                                  $query = "SELECT * FROM tbl_test WHERE identity = '$SomeVar'";

                                  $imagepath = "";

                                  $results = mysql_query($query);

                                  if($line = mysql_fetch_assoc($results)){

                                       echo "EMAIL:".$line["email"]."<br>";

                                       echo "IMAGE:".'<img src="'.$imagepath.$line["logo"].'" alt="" />'."<br>";

                                       echo "DATE_CREATED:".$line["date_created"]."<br>";

                                       echo "COMPANY:".$line["company"]."<br>";

                                       echo "ADDRESS:".$line["address"]."<br>";

                                       echo "PHONE:".$line["phone"]."<br>";

                                       echo "FAX:".$line["fax"]."<br>";

                                       echo "GENEMAIL:".$line["genemail"]."<br>";

                                  }

                                  mysql_close();

                                  ?>

                                  • 14. Re: Help with simple PHP
                                    Adamcbrz Level 2

                                    Here is a screenshot of the database record

                                    • 15. Re: Help with simple PHP
                                      Ron Colmen Level 2

                                        Hey Adam! Thanks!

                                       

                                      What about the actionscript? (How did you pull the image? and also how did you pull the data in to specified text boxes?)

                                       

                                      E.g.

                                      The Email in to "abc" text box

                                      The Company in to "def" text box

                                      The Fax in to "hij" text box

                                      The image in to "image" movie clip

                                      • 16. Re: Help with simple PHP
                                        Adamcbrz Level 2

                                        Ok what i suggest is converting you output into xml...much easier to parse with flash.

                                         

                                         

                                        if($line = mysql_fetch_assoc($results)){

                                        header("Content-type: text/xml");

                                        echo '<?xml version="1.0" encoding="utf-8"?>';

                                        echo "<item>";

                                        echo "<email>".$line["email"]."</email>";

                                        echo "<image>".$imagepath.$line["logo"]."</image>";

                                        echo "<datecreated>".$line["date_created"]."</datecreated>";

                                        echo "<company>".$line["company"]."</company>";

                                        echo "<address>".$line["address"]."</address>";

                                        echo "<phone>".$line["phone"]."</phone>";

                                        echo "<fax>".$line["fax"]."</fax>";

                                        echo "<genemail>".$line["genemail"]."</genemail>";

                                        echo "</item>";

                                        }

                                         

                                         

                                        This will render your values as xml. Then i would use an xml parser...you can do this with flash or i prefer http://blog.greensock.com/xmlparseras2/

                                         

                                        the actionscript would look something like...

                                         

                                        import gs.dataTransfer.XMLParser;

                                        XMLParser.load("test.php", onFinish);

                                        function onFinish($success:Boolean, $results:Object, $xml:XML):Void { //This function gets called when the XML gets parsed.    

                                             if ($success) {        

                                                  abc.text = $results.email[0].value;

                                                  def.text = $results.company[0].value;

                                                  hij.text = $results.company[0].value;

                                              

                                                            //load image code copied from adobe help http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00001381.html

                                                  var mclListener:Object = new Object();
                                                  mclListener.onLoadStart = function(target_mc:MovieClip) {
                                                      trace("onLoadStart");
                                                  };
                                                  mclListener.onLoadComplete = function(target_mc:MovieClip) {
                                                      trace("onLoadComplete");
                                                  };
                                                  mclListener.onLoadInit = function(target_mc:MovieClip) {
                                                      trace("onLoadInit");
                                                  };
                                                  var image_mcl:MovieClipLoader = new MovieClipLoader();
                                                  image_mcl.addListener(mclListener);
                                                  image_mcl.loadClip($results.image[0].value, image);

                                             }

                                        }

                                         

                                        That should do it...if you still don't see the image make the path to the image absolute instead of "images/logo.gif" make it "http://www.example.com/images/logo.gif"

                                         

                                        Enjoy!

                                        Adam

                                        • 17. Re: Help with simple PHP
                                          Ron Colmen Level 2

                                          Adam... THANKS A MILLION!!!!  but unfortunately XMLParser – Painless XML Translation could not be downloaded.

                                           

                                          How could I get it? could you attach it here? or any other recommended website to get it? or how could I do it in flash? I'd like to do it and see the results quickly!!! 

                                           

                                          Sorry for ALL THE TROUBLE, but I thank you form the bottom of my heart for helping me out!! 

                                          • 18. Re: Help with simple PHP
                                            Adamcbrz Level 2

                                            I will later tonight

                                             

                                            Thanks,

                                            Adam Brzozowski

                                            • 19. Re: Help with simple PHP
                                              Adamcbrz Level 2

                                              yeah there was a problem with javascript. Here is the url to download http://www.greensock.com/as/XMLParser/XMLParser.zip

                                              • 20. Re: Help with simple PHP
                                                Ron Colmen Level 2

                                                     

                                                THANK YOU ADAM!!

                                                 

                                                I'll set things up and let you know the results!!!

                                                 

                                                I assume the actionscript should be setup like this.

                                                 

                                                 

                                                sender.onRelease = function () {
                                                senderLoad.fin = fin.text;

                                                 

                                                import gs.dataTransfer.XMLParser;

                                                XMLParser.load("*test.php*", onFinish); function onFinish($success:Boolean, $results:Object,

                                                • 21. Re: Help with simple PHP
                                                  Ron Colmen Level 2

                                                  No success!! Nothing appears. Please see if I've done something wring with the scripts (marked in red)? I think the error is in the FLA.

                                                   

                                                  The gs and the logo image are in the dame folder. Empty movie clip (to load the logo.jpg) instance name is "target_mc:"

                                                   

                                                  PHP

                                                  <?php
                                                  $link = mysql_connect("localhost","abcd","dcba1");
                                                  mysql_select_db("abc_db");

                                                  $query = 'SELECT * FROM abtbl';
                                                  $results = mysql_query($query);

                                                  $imagepath = "";

                                                  $SomeVar = $fin; //some variable

                                                  $query = "SELECT * FROM abtbl WHERE identity = '$SomeVar'";
                                                  $results = mysql_query($query);
                                                  if($line = mysql_fetch_assoc($results)){
                                                  header("Content-type: text/xml");
                                                  echo '<?xml version="1.0" encoding="utf-8"?>';
                                                  echo "<item>";
                                                  echo "<email>".$line["email"]."</email>";
                                                  echo "<image>".$line["logo"]."</image>";

                                                  echo "<company>".$line["company"]."</company>";
                                                  echo "<address>".$line["address"]."</address>";
                                                  echo "<phone>".$line["phone"]."</phone>";
                                                  echo "<fax>".$line["fax"]."</fax>";
                                                  echo "<genemail>".$line["genemail"]."</genemail>";
                                                  echo "</item>";
                                                  }

                                                   

                                                  mysql_close($link);
                                                  ?>

                                                   

                                                   

                                                  AS

                                                  import gs.dataTransfer.XMLParser;
                                                  var senderLoad:LoadVars = new LoadVars();

                                                   

                                                  sender.onRelease = function () {
                                                  senderLoad.fin = fin.text;
                                                  senderLoad.sendAndLoad = XMLParser.load("
                                                  http://www.working.com/abc/info.php", onFinish);
                                                  function onFinish($success:Boolean, $results:Object, $xml:XML):Void {
                                                    if ($success) {

                                                    tf.text = $results.email[0].value;
                                                    com.text = $results.company[0].value;
                                                    addrr.text = $results.company[0].value;
                                                   
                                                    var mclListener:Object = new Object();
                                                    mclListener.onLoadStart = function(target_mc:MovieClip) {
                                                    trace("onLoadStart");
                                                    };
                                                    mclListener.onLoadComplete = function(target_mc:MovieClip) {
                                                      trace("onLoadComplete");
                                                      };
                                                      mclListener.onLoadInit = function(target_mc:MovieClip) {
                                                      trace("onLoadInit");
                                                      };
                                                      var image_mcl:MovieClipLoader = new MovieClipLoader();
                                                      image_mcl.addListener(mclListener);
                                                      image_mcl.loadClip($results.image[0].value, image);
                                                      }
                                                      }
                                                      gotoAndStop(5);
                                                    }

                                                  stop();

                                                  • 23. Re: Help with simple PHP
                                                    Ron Colmen Level 2

                                                    NO that's not a valid URL. But my script is as shown inmy previous post.

                                                     

                                                    The PHP shows the details (image as a url). - screenshot attached.

                                                    Flash Dosen't show anything.

                                                     

                                                    As in my very first post pulling the image to flash is still the problem here. Do you find any fault in the script above? Any idea why this is happening.

                                                    • 24. Re: Help with simple PHP
                                                      Adamcbrz Level 2

                                                      Here is how i would change it.

                                                       

                                                       

                                                      import gs.dataTransfer.XMLParser;
                                                      var senderLoad:LoadVars = new LoadVars();

                                                       

                                                      sender.onRelease = function () {
                                                      senderLoad.fin = fin.text;
                                                      senderLoad.sendAndLoad =

                                                      XMLParser.load("http://www.working.com/abc/info.php?fin="+fin.text, onFinish);
                                                      function onFinish($success:Boolean, $results:Object, $xml:XML):Void {

                                                      /*This will let you know if your class is getting imported because it will at least output "xml:" if it can't find the url but if don't see any output in your output panel then its not finding the class.*/

                                                        trace("xml:"+$xml);
                                                        if ($success) {
                                                        tf.text = $results.email[0].value;
                                                        com.text = $results.company[0].value;
                                                        addrr.text = $results.company[0].value;

                                                        [...]

                                                      • 25. Re: Help with simple PHP
                                                        Ron Colmen Level 2

                                                        still it's the same. Are you sure our fla worked? Could you please send me the fla.

                                                         

                                                        But I think there's something wrong in the AS script. It display none of the data.

                                                         

                                                        Also here will "fin" be sent to the PHP to select the correct "identity" from the mysql. Anyway I tried by typing directly the values in php and testing. But still no data is been received by flash. Should the AS script be rewritten in some other way??

                                                         

                                                        ONE MORE THING IS THE "XMLParser" AS2 version? or AS3 version?

                                                        • 26. Re: Help with simple PHP
                                                          Adamcbrz Level 2

                                                          Ok i did miss something in your code but i have an example code for you so you can take it from here.

                                                          • 27. Re: Help with simple PHP
                                                            Ron Colmen Level 2

                                                            Can not open the ZIP. I'm using Winzip 12.1.

                                                             

                                                            Thank you!

                                                            • 28. Re: Help with simple PHP
                                                              Adamcbrz Level 2

                                                              Ok i am going to send you a Person Message with info on where to get the files

                                                              • 29. Re: Help with simple PHP
                                                                Ron Colmen Level 2

                                                                I received your mail. But there was no attachments in it!

                                                                • 30. Re: Help with simple PHP
                                                                  Adamcbrz Level 2

                                                                  If you didn't see i sent you a link in a pm

                                                                  • 31. Re: Help with simple PHP
                                                                    Ron Colmen Level 2

                                                                    Hello Adam.

                                                                     

                                                                    I received your 2nd mail with the link, but the link is not working there too.

                                                                     

                                                                    Thank you for using your valiuable time in trying to solve my problem. I could only offer 2 helpful answer points since I still have to figue it out. If not the thread will say "correct answer".

                                                                     

                                                                    Thank you bro!

                                                                     

                                                                    • 32. Re: Help with simple PHP
                                                                      Adamcbrz Level 2

                                                                      I am going to send you another PM so we can im on skype or something.

                                                                      • 33. Re: Help with simple PHP
                                                                        Ron Colmen Level 2

                                                                        Thanks Adam!!!! That was Brillient!!!

                                                                         

                                                                        10/10

                                                                         

                                                                        Cheers bro!

                                                                         

                                                                        • 34. Re: Help with simple PHP
                                                                          Adamcbrz Level 2

                                                                          Glad to help where i can.