sending and receiving variables to and from a PHP file

Commenta 14th November , 2009
Hello everybody,
I’m trying to create a file that shows data from a database depending on an id number the user inputs in Flash. I am having trouble sending to PHP the id so it sends back the appropriate data from the db.

This is the AS3 code that tries to send the value of the idNumber to PHP:

ActionScript Code:
var myURLRequest:URLRequest = new URLRequest("http://localhost/flash_php/AS3/delete.php"); var myVariables:URLVariables = new URLVariables(); var myLoader:URLLoader = new URLLoader(); myURLRequest.data = myVariables; myURLRequest.method = URLRequestMethod.POST; myLoader.dataFormat = URLLoaderDataFormat.VARIABLES; var idNumber:Number; send_btn.addEventListener(MouseEvent.CLICK, sendId); delete_btn.addEventListener(MouseEvent.CLICK, deleteRecord); function sendId(e:MouseEvent):void{         idNumber = Number(id_txt.text);     myVariables.myId = idNumber;        //This traces correctly     /*trace(myVariables.myId );*/     myLoader.load(myURLRequest);     myLoader.addEventListener(Event.COMPLETE, showRecord);     } function showRecord(e:Event):void{      name_txt.text = myLoader.data.myname;     /*age_txt.text = myLoader.data.edad;     postcode_txt.text = myLoader.data.codigopostal;     email_txt.text = myLoader.data.email;*/     }

Also, when loading the data from PHP I get a Error #2101: The String passed to URLVariables.decode() must be a URL-encoded query string containing name/value pairs. Although, I believe, I’m sending the PHP variables correctly for AS3:

This is the PHP:

PHP Code:


<?php

session_start();

require_once 
"conexion.php";

$myId $_POST['$myId'];

$sqlC "SELECT * FROM contactos WHERE id='$myId'";

    

$q mysqli_query ($myConnection$sqlC);

while(
$showDetails mysqli_fetch_array($q)){

        

echo "myname=".$showDetails['nombre']."&age=".$showDetails['edad']."&postcode=".$showDetails['codigopostal']."&email=".$showDetails['email'];

    

    

    

    

    }

?>


To summarize I want the idNumber to be sent to the PHP file once the user clicks on the send_btn. Then the PHP file selects from the db the appropriate record according to the id number and echoes the results to Flash which in turn, shows the data in the appropriate textfields.

Can you help?. This is obviously not working :confused:

Million thanks,

txusm

Original post by txusm

Lascia un Commento