我想創建一個客戶端的swf文件,該文件使用php將文本字段的數據發送到我的服務器上的數據庫。我可以讓swf與另一臺服務器上的php文件進行通信嗎?
我的代碼工作正常,當我上傳到我的服務器上,但我想發送swf文件到客戶端,並讓swf與我的服務器上的php文件進行通信。
我該做些什麼來完成這項工作?即使我不知道客戶端放置swf的域名,這是否可能?
這是我的AS3代碼:
// Assign a variable name for our URL Variables object
var variables:URLVariables = new URLVariables();
// Build the varSend variable
var varSend:URLRequest = new URLRequest("databaseTest.php");
varSend.method = URLRequestMethod.POST;
varSend.data = variables;
// Build the varLoader variable
var varLoader:URLLoader = new URLLoader;
varLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
varLoader.addEventListener(Event.COMPLETE,completeHandler);
// Handler for PHP script completion and return
function completeHandler(event:Event):void{
//clear the form fields
name_txt.text = "";
lastName_txt.text = "";
mail_txt.text = "";
status_txt.text = "Thanks";
}
// Add an event listener for the submit button and what function to run
submit_btn.addEventListener(MouseEvent.CLICK,ValidateAndSend);
// Validate form fields and send the variables when submit button is clicked
function ValidateAndSend(event:MouseEvent):void {
// validate all the form fields
if(!name_txt.length){
status_txt.text = "name";
}else if(!lastName_txt.length){
status_txt.text = "last name";
}else if(!mail_txt.length){
status_txt.text = "mail";
}else{
// All is good so send the message to the parse file
//Ready the variables for sending
variables.comType = "parseInformation";
variables.sendName = naam_txt.text;
variables.sendLastName = achternaam_txt.text;
variables.sendEmail = mail_txt.text;
//Send the data to the php file
varLoader.load(varSend);
}
}
,這是PHP代碼:
<?php
// Connect to MySQL database
mysql_connect("localhost","*******","********") or die (mysql_error());
mysql_select_db("*******") or die (mysql_error());
if($_POST['comType'] == "parseInformation") {
$name = $_POST['sendName'];
$lastName = $_POST['sendLastName'];
$email = $_POST['sendEmail'];
$sql = mysql_query("INSERT INTO databaseTest (name, lastName, mail)
VALUES('$name', '$lastName', '$email')")
or die (mysql_error());
mysql_close();
exit();
}
?>