Solved

Send an XML object or file to a PHP script

Posted on 2010-08-12
7
441 Views
Last Modified: 2013-11-11
As simple as this sounds, for some reason I can't get my code to work.  What i am trying to do is have my flash program send an XML object or file to a PHP script to be read and logged into a MySQL database.  I know how to handle the MySQL, and I'd like to say that my PHP is fine too, but at this point I'm not certain.
/* Begin ActionScript 2.0 */

var input_xml = new XML()
input_xml.ignoreWhite = true
input_xml.contentType = "text/xml"

var xml = "http://j2imedia.com/kioskadmin/inc/layout.xml"
var php = "http://j2imedia.com/kioskadmin/inc/layout.php?user=" + user

save_button.onRelease = function(){
	trace(substring(master, 0, master.length - 1))
	input_xml.firstChild.firstChild.nodeValue = substring(master, 0, master.length - 1)
	input_xml.sendAndLoad(server_file, output_xml)
	//input_xml.send(php)
}

input_xml.onLoad = function(success){
	if(success){ trace(this.firstChild.firstChild.nodeValue) }
	else{ trace("Error loading input XML") }
}

/* End Actionscript 2.0 */

/* Start PHP */
<?php
	mysql_connect(localhost,"aquasius","launchme8804");
	mysql_select_db("Aquasius") or die("Unable to select database");
	
	$result = mysql_fetch_array(mysql_query('SELECT hash FROM users WHERE user = "' . $_GET['user'] . '"'));
	
	if($result[0] == $_GET['hash']){ $result = 'good'; }
	else{ $result = 'bad'; }

	echo '<?xml version="1.0"?>';
	echo "\t<list>";
	echo "\t\t<hash>" . $result . '</hash>';
	echo "\t</list>";
	echo '</xml>';
?>

Open in new window

0
Comment
Question by:nero777x
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 2

Expert Comment

by:badgerfoxfoxdeer
ID: 33425199
I'm not sure what your trying to do with your echo construct, just output the value to screen? there are issues with using echo like this (see http://php.net/manual/en/language.basic-syntax.php) maybe you need to use the asXML method?:

echo $xml->asXML();

You can also give it a filename

$xml->asXML('filename.xml');

let me know if this solves your problem or if you need more help

Cheers
0
 
LVL 34

Expert Comment

by:Beverley Portlock
ID: 33425221
Two things:

1) I hope that isn't your real database username and password - this is a PUBLIC forum

2) Are you urlencoding the XML in the flash before sending it? I don't know enough about actionscript to tell, but I cannot see anything that looks like encoding
0
 

Author Comment

by:nero777x
ID: 33426739
Sorry, I made a mistake.  I accidentally copied the wrong php file.  This is the correct file.  And no, the password is not my real password.
<?php
	mysql_connect(localhost,"aquasius","houseclear2401")
	mysql_select_db("Aquasius") or die("Unable to select database")

	$filename = 'layout.xml'
	$raw_xml = file_get_contents("php://input")

	print $raw_xml

	$fp = fopen($filename, "w")
	fwrite($fp, $raw_xml)
	fclose($fp)
?>

Open in new window

0
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 

Author Comment

by:nero777x
ID: 33428699
I need help fast, now.  This is a time sensitive project I'm working on.  So I hope raising the point cap will suffice.
0
 

Author Comment

by:nero777x
ID: 33429870
The input_xml.onLoad function doesn't seem to be in use ever.  When I push the button to create the XML, no traces come from that function.  A clue, perhaps?
0
 

Accepted Solution

by:
nero777x earned 0 total points
ID: 33432287
OK, problem fixed.  It turns out that I didn't have the semi-colons at the end of each line in the PHP file, as seen above.  Stupid mistake on my part, since I've been working with PHP for while now.
0
 
LVL 2

Expert Comment

by:badgerfoxfoxdeer
ID: 33435757
It's always the small things just glad you got it fixed, have you considered / have you a decent debugger? I use netbeans with xdebug think you can use it with eclipse too

Cheers
0

Featured Post

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
These days socially coordinated efforts have turned into a critical requirement for enterprises.
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question