我是两种编程语言的新手,可以使用任何可能的帮助。我在 AS3 中创建了一个表单,数据应该先发送到 PHP,然后再发送到 MYSQL。我检查了我的代码,在 PHP 文档或 AS3 文档中都没有错误。
我正在使用 WAMP Server 2.2,并且我确定我的文档是正确的WAMP/WWW/Project
(文档在此文件夹中)。我可以通过访问它们,http://localhost
但没有发送数据。
这是我对 PHP 和 AS3 的编码
AS3:
// hide processing CM
processing_mc.visible = false;
var variables:URLVariables = new URLVariables();
// Build the varSend variable
var varSend:URLRequest = new URLRequest("http://localhost/belitefitness/form.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 the PHP script completion and return of status
function completeHandler(event:Event):void {
// remove processing clip
processing_mc.visible = false;
firstname_txt.text = "";
lastname_txt.text = "";
email_txt.text = "";
number_txt.text = "";
msg_txt.text = "";
// Load the response from php here
status_txt.text = event.target.data.return_msg;
}
// Add event listener for submit button click
submit_btn.addEventListener(MouseEvent.CLICK, ValidateAndSend);
// function ValidateAndSend
function ValidateAndSend (event:MouseEvent):void {
// validate fields
if(!firstname_txt.length) {
status_txt.text = "Please enter your First Name";
} else if (!lastname_txt.length) {
status_txt.text = "Please enter your Last Name";
} else if (!email_txt.length) {
status_txt.text = "Please enter your Email";
} else if (!number_txt.length) {
status_txt.text = "Please enter your Phone Number";
} else {
// All is good, send the data now to PHP
processing_mc.visible = true;
// ready the variables in our form for sending
variables.userFirstName = firstname_txt.text;
variables.userLastName = lastname_txt.text;
variables.userEmail = email_txt.text;
variables.userNumber = number_txt.text;
variables.userMsg = msg_txt.text;
// Send the data to PHP now
varLoader.load(varSend);
} // close else condition for error handling
} // close validate and send function
PHP
<?php
if(isset($_POST['userFirstName']) && isset($_POST['userLastName']) && isset($_POST['userEmail']) && isset($_POST['userNumber']) && isset($_POST['userMsg']))
{
$userFirstName=strip_tags($_POST['userFirstName']);
$userLastName=strip_tags($_POST['userLastName']);
$userEmail=strip_tags($_POST['userEmail']);
$userNumber=strip_tags($_POST['userNumber']);
$userMsg=strip_tags($_POST['userMsg']);
// connect with database.
$username="root";
$password="dp10aap";
$database="b-elite-fitness";
mysql_connect("localhost","$username","$password") or die (mysql_error());
mysql_select_db("$database") or die (mysql_error());
//query for inserting data in database.
$query="INSERT INTO 'formdp' VALUES('NULL','".mysql_real_escape_string($userFirstName)."','".mysql_real_escape_string($userLastName)."','".mysql_real_escape_string($userEmail)."','".mysql_real_escape_string($userNumber)."','".mysql_real_escape_string($userMsg)."')";
if($query_run=mysql_query($query))
{
echo'Data inserted.';
} else {
die(mysql_error());
}
}
?>