flex php 상호작용

20332 단어 Flex
주소
데이터베이스 tiask 를 만 들 고 다음 sql 을 실행 합 니 다.
/*
Navicat MySQL Data Transfer

Source Server : localhost
Source Server Version : 50067
Source Host : localhost:3306
Source Database : tiask

Target Server Type : MYSQL
Target Server Version : 50067
File Encoding : 65001

Date: 2011-10-09 16:59:33
*/

SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
--
Table structure for `flextest`
--
----------------------------
DROP TABLE IF EXISTS `flextest`;
CREATE TABLE `flextest` (
`name` varchar(10) NOT NULL,
`pwd` longtext,
PRIMARY KEY (`name`)
) ENGINE=MyISAM DEFAULT CHARSET=gb2312;

-- ----------------------------
--
Records of flextest
--
----------------------------
INSERT INTO `flextest` VALUES ('user', '1234');

-- ----------------------------
--
Table structure for `user_list`
--
----------------------------
DROP TABLE IF EXISTS `user_list`;
CREATE TABLE `user_list` (
`name` longtext,
`pwd` longtext
) ENGINE=MyISAM DEFAULT CHARSET=gb2312;

-- ----------------------------
--
Records of user_list
--
----------------------------
INSERT INTO `user_list` VALUES ('user', '1234');

flex 부분:
<?xml version="1.0" encoding="utf-8"?> 
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.rpc.events.ResultEvent;
import mx.controls.Alert;
[Bindable]
private var result1:ArrayCollection;
private var login_result:String;
[Bindable]
private var sendChoice:String;
private function goLogin():void{
if(username.text=="" || userpwd.text=="")
Alert.show(" ");
else{
sendChoice="login";
login.send();
}
}
private function goRegis():void{
if(username.text=="" || userpwd.text=="")
Alert.show(" ");
else{
sendChoice="regis";
login.send();
}
}

private function resultHandler(event:ResultEvent):void{
login_result=event.result.html.body.users.a.toString();
if(login_result=="ok"){
Alert.show(" , ");
}
if(login_result=="nohave"){
Alert.show(" !");
}
if(login_result=="pwderror"){
Alert.show(" ! !");
}
if(login_result=="nameishave"){
Alert.show(" , ");
}
if(login_result=="regisok"){
Alert.show(" , ");
}
if(login_result=="error"){
Alert.show(" ");
}
}
]]>
</mx:Script>
<mx:HTTPService id="login" method="POST" showBusyCursor="true" url="http://localhost/testflex.php"
result
="resultHandler(event)">
<mx:request xmlns="">
<mx:username>
{username.text}
</mx:username>
<mx:userpwd>
{userpwd.text}
</mx:userpwd>
<mx:sendchoice>
{sendChoice}
</mx:sendchoice>
</mx:request>
</mx:HTTPService>
<mx:Panel width="310" height="265" layout="absolute" title=" " fontSize="12" fontWeight="normal">
<mx:TextInput x="93" y="51" id="username" fontSize="12" restrict="0-9,a-z" maxChars="8"/>
<mx:TextInput x="92" y="95" id="userpwd" fontSize="12" displayAsPassword="true" maxChars="8" restrict="0-9,a-z"/>
<mx:Button x="78" y="154" label=" " id="btn1" click="goLogin()" fontWeight="normal" fontSize="12"/>
<mx:Label x="32" y="53" text=" :" fontSize="12"/>
<mx:Label x="43" y="97" text=" :" fontSize="12"/>
<mx:Button x="154" y="154" label=" " fontSize="12" fontWeight="normal" id="btn2" click="goRegis()"/>
<mx:Label x="10" y="10" text=" user 1234" fontSize="12" width="243"/>
</mx:Panel>
</mx:Application>

php 부분:e
testflex.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>flex login</title>
</head>

<body>
<?php
$return="";
if(isset($_POST[username]) && isset($_POST[userpwd]) && isset($_POST[sendchoice])){
$uname=$_POST[username];
$upwd=$_POST[userpwd];
$choice=$_POST[sendchoice];
$link = mysql_connect("localhost","root","") or die (mysql_error());
if($link){
$select=mysql_select_db("tiask",$link);
mysql_query("set names gb2312");
if($choice=="login"){
$sql=mysql_query("select * from flextest where name='$uname'");
$result=mysql_fetch_object($sql);
if($result==false){
$return='<users>';
$return.='<a>nohave</a>';
$return.='</users>';
}else if($result->pwd==$upwd){
$return='<users>';
$return.='<a>ok</a>';
$return.='</users>';
}else{
$return='<users>';
$return.='<a>pwderror</a>';
$return.='</users>';
}
}
if($choice=="regis"){
$sql=mysql_query("select * from user_list where name='$uname'");
$result=mysql_fetch_object($sql);
if($result==false){
$sql_1=mysql_query("insert into user_list(name,pwd) values('$uname','$upwd')",$link);
if($sql_1){
$return='<users>';
$return.='<a>regisok</a>';
$return.='</users>';
}
}else{
$return='<users>';
$return.='<a>nameishave</a>';
$return.='</users>';
}
}
}
mysql_close();
} else{
$return='<users>';
$return.='<a>error</a>';
$return.='</users>';
}

echo $return;
?>
</body>
</html>

완전무결 하 다

좋은 웹페이지 즐겨찾기