0

So, here is the question. I have a small flash application that sends some variables to a php script (via POST), and that php script sends them to a mySQL database.

This works fine when I'm testing my flash offline, I go to phpmyadmin, and the registry is done. When I upload the swf to a online html, this stops working. It no longer creates another registry in the database. I have no ideia why this happens.

I read a bit about it and found out about cross domain policy, and thought it might be the problem. Thus I made a small .xml file and uploaded it to both servers (the one the swf is on, and the one that has the database), and its still not working.

Here is my crossdomain.xml file (named that way):

 <?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<allow-access-from domain="*" />
</cross-domain-policy> 

And the php (named insert.php), that is on the same server as the database:

<?php

//connect to the local MySQL
$connect=mysql_connect("localhost", "DBName", "DBPass");

//select your database
mysql_select_db("DBTable");

//query the database
$query="INSERT INTO results(Nome,Email,Idade,Profissao,Pais)
VALUES
('$_POST[nome]','$_POST[email]','$_POST[idade]','$_POST[profissao]','$_POST[pais]')";


//$result=mysql_query($query);

if (!mysql_query($query,$connect))
{
    die('Error: ' . mysql_error());
    echo "InsertOk=NotOk";
}else{
    echo "InsertOk=Ok";
}

mysql_close($connect)
?>

Thank you! Marco Roberto

FoxLift
  • 433
  • 2
  • 16
  • 30

1 Answers1

2

Apart from obvious security flaws, try to

"INSERT INTO results(Nome,Email,Idade,Profissao,Pais)
VALUES
('{$_POST['nome']}','{$_POST['email']}','{$_POST['idade']}','{$_POST['profissao']}','{$_POST['pais']}')";

Basicly add {} and ''.

EDIT:
Nevermind that part. Noticed it's not relevant.

I believe you have to do the call to your own site, and use CURL to pass $_POST-values to the other domain.

Try this answer
Even though this is for javascript, I belive the same rules apply for your swf file.

Community
  • 1
  • 1
Robin Castlin
  • 10,956
  • 1
  • 28
  • 44
  • I am aware this code has problems with sql injections, but I'm just trying to get it working meanwhile. I'm also fairly noob in php/mySQL, so I'm trying to tackle one problem at a time. Also, this works when I'm testing the app offline sending variables to the online server, so I guess it is getting the POST values correctly, just doesen't work online for some reason. Security issues maybe? – FoxLift Apr 16 '12 at 09:37
  • It's the crossdomains issue. Basicly you need to call a php script on the same domain as your .swf, which then does a CURL with the same values to the other domain. Take a lot at my updated answer. – Robin Castlin Apr 16 '12 at 09:43