dcsimg
A Flash Developer Resource Site

Results 1 to 14 of 14

Thread: [RESOLVED] Is this because of Incorrect Datatype?

  1. #1
    Banned
    Join Date
    Mar 2009
    Posts
    153

    resolved [RESOLVED] Is this because of Incorrect Datatype?

    Which datatype should I be using to store xml String into my mySQL database? I tried using TEXT datatype. But my flash is unable to parse it.
    I am not sure if this is because of incorrect datatype usage.

    I keep getting "Error in Source Data" inside my flash textfield when the xml string is echo'd from php. I was able to trace this echo'd xml string in my output panel. But when I tried testing the same XML code(by copying xml string from the output panel and pasting into a new XML file in my hard disk) and load it through myxml.load() method, it works great...


    This is the code I have in Flash(Cs3-As2)

    Code:
    var xmlLoadVars = new LoadVars();
    xmlLoadVars.onLoad = function(suc) {
    	if (suc) {
    		if (this.statusmsg == "exists") {
    			var getBlogString = '<?xml version="1.0" ?>'+newline+this.blogentry;
    			myxml = new XML(getBlogString);
    			xmlparser(myxml);
    			trace("Loaded XML from SQL:\n\n");
    		} else {
    			showerrorlog(this.statusmsg);
    		}
    	} else {
    		showerrorlog("Connection Error. Unable to Login");
    	}
    };
    
    xmlLoadVars.uid = blogsource;
    xmlLoadVars.sendAndLoad("myPhpFile.php",xmlLoadVars,"POST");
    
    
    var myxml=new XML();
    myxml.ignoreWhite = true;
    
    function xmlparser(theXml) {
    if (theXml.firstChild.nodeName == "noteblog_source" && theXml.firstChild.childNodes.length == 2) {
    		//trace("---------------------------------\n\n"+theXml+"\n\n\n\n---------------------------------");		
    		blogurl.text = "login success!";
    		
    	} else {
    		blogurl.text ="Error in Source Data"; //
    	}
    
    }

    This is my php Code:


    Code:
    <?php
    $link3=mysql_connect("host","abcd","passwd");
    		if($link3){
    			if(mysql_select_db("mydb",$link3)){
    			$myquery3=mysql_query("SELECT * FROM mytable WHERE username='$_POST[uid]'");	
    				$check_avail3=false;
    				while($row = mysql_fetch_array($myquery3)){	
    				$check_avail3=true;
    				  echo "statusmsg=exists";
    				  echo "&blogentry=".$row['blogcontent']; 
    				}
    				if(!$check_avail3){
    					echo "statusmsg=Invalid Login ID";
    				}
    			}else{
    				echo "statusmsg=Unable to connect to database, please try later";
    			}
    		}else{
    			echo "statusmsg=Server busy, please try later";
    		}
    		
    		
    ?>
    Please suggest.

  2. #2
    Bearded (M|G)od MyFriendIsATaco's Avatar
    Join Date
    Dec 2002
    Location
    Awesomeville.
    Posts
    3,046
    For one, you're trying to mix XML and string outputs. That's weird. Either do all XML, or all string. And what I mean by that is your output may look something like:
    Code:
    statusmsg=exists&blogentry=<entry><blah>yay!</blah></entry>
    From PHP, you can output raw XML and that's all you should be doing. Something like:
    Code:
    <?xml version="1.0" ?>
    <response>
        <status>1</status>
        <blog>
            <entries>
                <entry>Hey, this is my blog!</entry>
            <entries>
        </blog>
    </response>

  3. #3
    Banned
    Join Date
    Mar 2009
    Posts
    153
    Lovely

    Silly me.. I will check that out.

    Thank You

  4. #4
    Banned
    Join Date
    Mar 2009
    Posts
    153

    Unhappy Not yet..

    Hmm...
    I changed the flash code to:

    Code:
    xmlLoadVars.onLoad = function(suc) {
    if (suc) {
    var getBlogString = '<?xml version="1.0" ?>'+newline+this;
    	myxml = new XML(getBlogString);
    	xmlparser(myxml);
    	trace("Loaded XML from SQL:\n\n");
    }else{
    trace("failed to load");
    }
    }
    And in my php...

    Code:
    while($row = mysql_fetch_array($myquery3)){	
    		$check_avail3=true;				  
    		echo $row['blogcontent']; 
    }
    My output panel shows:
    Code:
    <?xml version="1.0" ?>
    %3Cnoteblog%5Fsource%3E%0D%0A%3CBlogsettings%20isBlogTextSelectable=%27no%27%20BackgroundMp3Music%3D%27http%3A%2F%2F%2E%2Ecom%2Fam%2F%2Emp3%27%20BackgroundImage%3D%27http%3A%2F%2Fsos%2Enoaa%2Egov%2Fimages%2Ffullsize%2FLand%2FearthAtNight%2Ejpg%27%20ScaleBackgroundImage%3D%27no%27%20ShowBlogBorder%3D%27yes%27%20BlogColor%3D%27333333%27%20BlogTextColor%3D%27FF6666%27%20BlogTitleColor%3D%2733990%27%3E%0D%0A%3CMyProfile%20YourName%3D%27DeCOr%27%20YourEmail%3D%27something%40gmail%27%20ProfileImage%3D%27http%3A%2F%2Fcardboardmonocle%2Ecom%2Fblog%2Ffxsuits%2Fal1%2Ejpg%27%20ProfileColor%3D%27000000%27%20ProfileTextColor%3D%27999999%27%3E%3C%21%5BCDATA%5BHey%20dude%2C%20How%20is%20this%20cool%20profile%2E%3Cbr%2F%3E%3Cbr%2F%3E%3Cbr%2F%3E%3Cbr%2F%3E%0D%0A%3Ca%20href%3D%27http%3A%2F%2Fcardboardmonocle%2Ecom%2Fblog%2Ffxsuits%2Falien1%2Ejpg%27%3EThis%3C%2Fa%3E%20is%20the%20pic%0D%
    
    ....
    ......
    .........
    (goes on.....)
    Last edited by e_tit; 10-09-2009 at 11:11 AM.

  5. #5
    Bearded (M|G)od MyFriendIsATaco's Avatar
    Join Date
    Dec 2002
    Location
    Awesomeville.
    Posts
    3,046
    Right, it's urlencoding your XML. That's why you should send back raw XML and not load it with LoadVars. Load it in with the XML class instead. Spit back the entire <?xml version="1.0" ?> string from PHP too, and sent the Content-type header to: text/xml.

  6. #6
    Banned
    Join Date
    Mar 2009
    Posts
    153
    How do i do that?
    Should i include Content-type=text/xml? in php like this?

    Code:
    while($row = mysql_fetch_array($myquery3)){	
    				$check_avail3=true;		
    				header("Content-type: text/xml");
    				 echo '<?xml version="1.0" encoding="UTF-8" ?>'.$row['blogcontent']; 
    }
    In my Flash:

    Code:
    xmlLoadVars.onLoad = function(suc) {
    	if (suc) {			
    			myxml.load(this)
    			//xmlparser(myxml);
    			trace("Loaded XML from SQL:\n\n");
    		}
    	} else {
    		showerrorlog("Connection Error. Unable to Login");
    	}
    };
    var myxml=new XML();
    myxml.ignoreWhite = true;
    myxml.onLoad = function(success) {
    	if (success) {
    		if (this.status == 0) {
    			xmlparser(this);
    		} else {
    			showerrorlog("Error in Source Data");
    		}
    	} else {
    		showerrorlog("Incorrect path. Please check");
    	}
    };
    I get Loaded XML from SQL: in my output panel.
    And nothing shows up after that

  7. #7
    Bearded (M|G)od MyFriendIsATaco's Avatar
    Join Date
    Dec 2002
    Location
    Awesomeville.
    Posts
    3,046
    echo '<?xml version="1.0" encoding="UTF-8" ?>'.$row['blogcontent'];


    That line is inside your loop, so you are having a new xml declaration for each entry. You also have improper XML structure now. You need some more DOM elements.

  8. #8
    Banned
    Join Date
    Mar 2009
    Posts
    153
    That loops only once. Its just to read blogcontent of one particular user... I even traced the output to confirm

    I also tried changing the Collation from Latin to Utf-8 in my sql table

    Now my flash code looks like this...
    Code:
    var getBlogString = this.blogcode;
    myxml = new XML(getBlogString);
    xmlparser(myxml);
    function xmlparser(theXml) {
    trace(theXml);
    if (theXml.firstChild.nodeName == "noteblog_source" && theXml.firstChild.childNodes.length == 2) {
    trace("WORKS");
    }else{
    trace("NOT WORKING");
    }
    I added <?xml version='1.0' encoding='UTF-8' ?> in the Original xml string which is in the database.

    Php code:
    Code:
    while($row = mysql_fetch_array($myquery3)){	
    $check_avail3=true; 
    echo "blogcode=".$row['blogcontent']; 
    }

    In my output Panel I get the complete xml string traced without any trouble. But I am unable to parse/access the nodes. When I copy paste this traced output into a seperate notepad file and load it through xml.onLoad(), I dont have trouble accessing the nodes
    Last edited by e_tit; 10-10-2009 at 04:43 AM.

  9. #9
    Banned
    Join Date
    Mar 2009
    Posts
    153

    Thumbs up Got it working

    Thanks Taco

    Code:
    var myxml=new XML();
    myxml.ignoreWhite = true;
    
    function xmlparser(theXml) {
    if (theXml.firstChild.nodeName == "noteblog_source" && theXml.firstChild.childNodes.length == 2) {			
    		blogurl.text = "login success!";
    		
    	} else {
    		blogurl.text ="Error in Source Data"; 
    	}
    
    }
    myxml.onLoad = function(success) {
    	if (success) {
    		if (this.status == 0) {
    			xmlparser(this);
    		} else {
    			showerrorlog("Error in Source Data");
    		}
    	} else {
    		showerrorlog("Incorrect path. Please check");
    	}
    };
    myxml.load("myPhpFile.php?uid="+blogsource);

    But is this the only way I can pass variable(uid) to my php if i am using xml.load() method?
    Here "uid" is a variable that holds the username. Php file checks for this user name in database and echos back the blog content of that particular user.


    [EDITED] I also have a password variable. Is there a better way to pass this variable to my php so that I get the XML echo'd back to flash all at the same time?
    Last edited by e_tit; 10-10-2009 at 12:01 PM.

  10. #10
    Bearded (M|G)od MyFriendIsATaco's Avatar
    Join Date
    Dec 2002
    Location
    Awesomeville.
    Posts
    3,046
    You could use sendAndLoad to POST data to your PHP script.

  11. #11
    Banned
    Join Date
    Mar 2009
    Posts
    153
    yeah, but how do I get the xml string echo'd back to flash if I use LoadVars? It doesn't seem to work when I tried it before

  12. #12
    Bearded (M|G)od MyFriendIsATaco's Avatar
    Join Date
    Dec 2002
    Location
    Awesomeville.
    Posts
    3,046
    If you're loading XML, you should be using the appropriate XML classes. But to answer your question, when you're loading through LoadVars and NOT using raw XML, your strings get URL encoded, hence why you're getting all of the %3C & %5F mess. To fix that, Flash has a function unescape().

    So if you're doing this:
    Code:
    var getBlogString = '<?xml version="1.0" ?>'+newline+this.blogentry;
    Your new code would be:
    Code:
    var getBlogString = '<?xml version="1.0" ?>'+newline+unescape(this.blogentry);

  13. #13
    Bearded (M|G)od MyFriendIsATaco's Avatar
    Join Date
    Dec 2002
    Location
    Awesomeville.
    Posts
    3,046
    Oh, and incase I wasn't clear about the sendAndLoad: sendAndLoad is also a method of the XML class. http://www.adobe.com/support/flash/a...ionary856.html

  14. #14
    Banned
    Join Date
    Mar 2009
    Posts
    153
    Worked

    Thank you

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