Skip to main content
Participating Frequently
January 16, 2011
Question

simple insert into MYSQL from Flash via PHP

  • January 16, 2011
  • 2 replies
  • 4675 views

Hi There,

I have spent many days tearing my hair out trying to get this simple flash code to work.

I have four text fields named player,tournament,position,prize and a submit button.

I have a working mysql database. The php file without the POST variables (i.e. using static data) works fine.

I just cannot get the flash to talk to the php correctly. I have looked at many examples and tutorials and forums, but am at a loss.

I have had many flash errors over the days. At the moment it is ArgumentError: Error #1063: Argument count mismatch on actions::main/processLogin(). Expected 0, got 1

Any help would be amazing!

[CODE]<?php

$player = $_POST['player'];

$tournament = $_POST['tournament'];

$position = $_POST['position'];

$prize = $_POST['prize'];

mysql_connect("localhost", "root","poker");

mysql_select_db("poker");

mysql_query("INSERT INTO results(player,tournament,position,prize) VALUES

('$player','$tournamnet','$position','$prize')");

?>[/CODE]

package actions {

import flash.display.MovieClip;

import flash.events.*;

import flash.net.*;

import flash.text.*;

public class main extends MovieClip {

public function main ():void {

submit_button.buttonMode = true;

submit_button.addEventListener(MouseEvent.MOUSE_DOWN, processLogin);

tournament.text = "";

player.text = "";

                        position.text = "";

                        prize.text = "";

}

public function processLogin ():void {

var phpVars:URLVariables = new URLVariables();

var phpFileRequest:URLRequest = new URLRequest("php/controlpanel.php");

phpFileRequest.method = URLRequestMethod.POST;

phpFileRequest.data = phpVars;

var phpLoader:URLLoader = new URLLoader();

phpLoader.dataFormat = URLLoaderDataFormat.VARIABLES;

phpVars.player = player.text;

phpVars.tournament = tournament.text;

phpVars.position = position.text;

phpVars.prize = prize.text;

phpLoader.load(phpFileRequest);

}

}

}

This topic has been closed for replies.

2 replies

January 17, 2011

When you connect to the database you need to store the connection in a variable for use in your query - like so:

$connection = mysql_connect("localhost", "root","poker");

And then use that in query:

mysql_query("INSERT INTO results(player,tournament,position,prize) VALUES ('$player','$tournamnet','$position','$prize')", $connection);

Participating Frequently
January 17, 2011

Hello there dmennenoh, welcome to my world of pain!

Have done what you said and still nothing updating.

openHandler: [Event type="open" bubbles=false cancelable=false eventPhase=2]

progressHandler loaded:13 total: 13

httpStatusHandler: [HTTPStatusEvent type="httpStatus" bubbles=false cancelable=false eventPhase=2 status=200 responseURL=null]

response from server:  result=theEnd

January 17, 2011

Then I would suggest changing your $_POST's to $_REQUEST's and testing via the query string - and tracing your SQL... something like:

<?php

$player = $_REQUEST['player'];

$tournament = $_REQUEST['tournament'];

$position = $_REQUEST['position'];

$prize = $_REQUEST['prize'];

$connection = mysql_connect("localhost", "root","poker");

mysql_select_db("poker");

$sql = "INSERT INTO results(player,tournament,position,prize) VALUES ('$player','$tournamnet','$position','$prize')"

mysql_query($sql, $connection);

echo($sql);

?>

and then test in browser like:

www.mydomain.com/myscript.php?player=pete&tournament=xxx&position=yyy&prize=zzz

Inspiring
January 16, 2011

Hi Dakky,

I suppose the function "processLogin" responds to a mouseclick thus expecting an event as parameter.

If I'm right, changing the line with the function signature to:

public function processLogin( event:MouseEvent ):void

should fix it.

hope it helps,

Manno

Participating Frequently
January 16, 2011

Thank you sir, gets rid of that error, but still does not make any addition to my database! :/

Inspiring
January 16, 2011

sometimes hard to debug yes.

You can get the response of the server by listening for the COMPLETE event of the URLLoader. When it is triggered, the response of the server is in it's data property. OTTOMH:

...

   phpLoader.addEventListener( Event.COMPLETE, onLoaded );

}

private function onLoaded( event:Event ):void

{

   trace ( "response from server: ", event.target.data );

}

Have the PHP output some sensible info on all it does and have server output it's errors so that everything that happens at the server is shown in the output.

Hope this helps,

Manno