Flash and php

Source: Internet
Author: User
Tags mysql connect
Flash and php p {margin-bottom: 0.08in ;}

Flash and asp:

Paste the following two codes:

Flash:

Webpage Tutorial network

Var loader: URLLoader = new URLLoader ();

Var url: URLRequest = new URLRequest ("test. asp ");

Url. method = URLRequestMethod. POST;

Var values: URLVariables = new URLVariables ();

Values. message = "hello im flash! ";

Url. data = values;

Loader. dataFormat = URLLoaderDataFormat. VARIABLES;

Loader. addEventListener (Event. COMPLETE, loaded );

Function loaded (e: Event ){

Out1.text = loader. data;

// OutPut: phpMessage = im php message! & FlashMessage = hello im flash!

Out2.text = loader. data. phpMessage;

// Im php message!

Out3.text = loader. data. flashMessage;

// Hello im flash!

Out4.text = loader. data. dbMessage;

}

Loader. load (url );

Webpage Tutorial network

Webpage Tutorial network

Asp:

Webjx. Com

<% @ LANGUAGE = "JAVASCRIPT" %>

<%

// Receives data from flash.

Var flashData;

FlashData = Request ("message ");

// Data sent to flash

Var aspMessage;

AspMessage = 'im asp message! ';

// Database operations

// ================================================

Var conn;

Var rs;

Var SQL;

Var strPath;

StrPath = "test. mdb ";

Try {

Conn = Server. CreateObject ("ADODB. Connection ");

Conn. connectionString = "Provider = Microsoft. Jet. OLEDB.4.0; Data Source =" + Server. MapPath (strPath );

Conn. open ();

} Catch (e ){

Response. Write ('

Database connection error. check the connection string!

');

Response. End

}

Rs = Server. createobject ("ADODB. Recordset ");

SQL = "select * from name ";

Rs. open (SQL, conn, 1, 1 );

// ================================================

Response. Write ("phpMessage =" + aspMessage + "&" + "flashMessage =" + flashData + "&" + "dbMessage =" + rs ("companyname "));

%>

Webjx. Com

When you see flash and asp files, the variable names will know how they are transmitted. for some database insertion, update, and query operations, you only need to receive flash data, you can directly run the asp-related database operation commands. directly copy to the IIS path to test. online viewing address: PLETE, loaded );

Function loaded (e: Event ){

Out1.text = loader. data;

// OutPut: phpMessage = im php message! & FlashMessage = hello im flash!

Out2.text = loader. data. phpMessage;

// Im php message!

Out3.text = loader. data. flashMessage; Webjx. Com

// Hello im flash!

Out4.text = loader. data. dbMessage;

}

Loader. load (url );

Php:

Webjx. Com

Webjx. Com

// Database operations are involved here

// ============================================

Define ('database _ server', 'localhost ');

Define ('database _ username', 'root ');

Define ('database _ password', 'root ');

Define ('database _ name', 'flextest ');

$ Link = @ mysql_connect (DATABASE_SERVER, DATABASE_USERNAME, DATABASE_PASSWORD );

@ Mysql_select_db (DATABASE_NAME, $ link );

$ Result = @ mysql_query ("Select * from users ");

$ User = @ mysql_fetch_array ($ result, MYSQL_ASSOC );

// Echo $ user ['userid'];

$ Dbvar = $ user ['userid'];

// ============================================

// Receives data from flash.

$ FlashData = $ _ POST ['message'];

// Data sent to flash

$ PhpMessage = 'im php message! ';

Echo "phpMessage = $ phpMessage & flashMessage = $ flashData & dbMessage = $ dbvar ";

?>

Webjx. Com

The code is very simple and does not need to be explained much. In fact, there are no major differences with asp. directly copy to the php path to test. the database file runs flextest directly under phpMyAdmin. the SQL statement in SQL is enough. because the company has disabled ports, I cannot operate SQL databases in my space online. I don't have an online demo address. I will add it at home when I have time.

Flex and php:

Paste the following two codes:

Flex:

Webjx. Com

Webjx. Com

</p> <p> public function onInit():void </p> <p> { </p> <p> userRequest.send(); </p> <p> } Webjx.Com </p> <p>

{Username. text} {Emailaddress. text}

Webjx. Com

Php:

Webpage Tutorial network

/* Thanks to Pete Macie for the code below */

Define ('database _ server', 'localhost ');

Define ('database _ username', 'root ');

Define ('database _ password', 'root ');

Define ('database _ name', 'flextest ');

# Connect to the database

$ Mysqli = new mysqli (DATABASE_SERVER, DATABASE_USERNAME, DATABASE_PASSWORD, DATABASE_NAME );

# Check connection

If (mysqli_connect_errno ()){

Printf ("MySQL connect failed: % s \ n", mysqli_connect_error ());

Exit ();

}

# Quote variable to make safe

Function quote_smart ($ value ){

Global $ mysqli;

Webjx. Com

# Stripslashes

If (get_magic_quotes_gpc ())

$ Value = stripslashes ($ value );

# Quote if not integer

If (! Is_numeric ($ value ))

$ Value = $ mysqli-> real_escape_string ($ value );

Return $ value;

}

If (! Empty ($ _ POST) & $ _ SERVER ['request _ method'] = 'post '){

If ($ _ POST ['emailaddress'] & $ _ POST ['username']) {Webpage Tutorial network

# Add the user

$ Query = sprintf ("Insert INTO users VALUES ('', '% s',' % s') ", quote_smart ($ _ POST ['username']), quote_smart ($ _ POST ['emailaddress']);

If (! @ $ Mysqli-> query ($ query )){

Printf ("'flextest' user database query insert error: % s \ n", $ mysqli-> error );

$ Mysqli-> close ();

Webjx. Com

Exit ();

}

}

}

# Return a list of all the users

If (! $ Result = @ $ mysqli-> query ("Select * from users ")){

Printf ("'flextest' user database query select error: % s \ n", $ mysqli-> error );

$ Mysqli-> close ();

Exit ();

}

$ Xml_return =" ";

While ($ user = mysqli_fetch_array ($ result, MYSQLI_ASSOC )){

$ Xml_return. = Webjx. Com

" ". $ User ['userid']." ". $ User ['username']." ". $ User ['emailaddress']." \ N ";

}

$ Xml_return. ="";

$ Mysqli-> close ();

Echo $ xml_return;

?>

The code here is an instance in Adobe phpria sdk. if you want all source code, please leave your email and I will send it. flex and php will not talk about it, just convert the php code into asp code, and work with flash.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.