Solved

Send an XML object or file to a PHP script

Posted on 2010-08-12
7
435 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
  • 4
  • 2
7 Comments
 
LVL 2

Expert Comment

by:badgerfoxfoxdeer
Comment Utility
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
Comment Utility
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
Comment Utility
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:nero777x
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.

763 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now