我是 Php 和 AS3 的新手,我正在尝试设置一个注册页面,AS3 会将数据发送到 php,然后它应该返回一条消息说您已成功注册。目前,AS3 确实将所有数据发送到数据库。但是AS3没有显示注册成功的消息,但也显示没有错误。请帮忙
我的 AS3 代码
stop();
// build variable name for the URL Variables loader
var variables:URLVariables = new URLVariables;
// Build the varSend variable
var varSend:URLRequest = new URLRequest("http://localhost/dummy.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 {
if(event.target.data && event.target.data.return_msg)
status_txt.text = event.target.data.return_msg
}
// Add event listener for submit button click
submit.addEventListener(MouseEvent.CLICK, ValidateAndSend);
// function ValidateAndSend
function ValidateAndSend (event:MouseEvent):void {
// validate fields
if(!name_txt.length) {
status_txt.text = "Please enter your name";
} else if (!email_txt.length) {
status_txt.text = "Please enter your email";
} else if (!pass_txt.length) {
status_txt.text = "Please enter your password";
} else {
// ready the variables in our form for sending
variables.username = name_txt.text;
variables.email = email_txt.text;
variables.password = pass_txt.text;
// if error occurs
// Send the data to PHP now
varLoader.load(varSend);
} // close else condition for error handling
}
下面是我的php代码
<?php
ini_set('display_errors', 1); error_reporting(E_ALL);
include 'connect.php';
{
//get form data
$username = ($_POST['username']);
$password = ($_POST['password']);
$email = ($_POST['email']);
if (!$username||!$password||!$email)
{
$fill= "Please fill out all fields";
echo ($fill) ;
}
else
{
//encrypt password
$password = md5($password);
//check if username already taken
$check = mysqli_query($con,"SELECT * FROM Test WHERE username = '$username'") or die( mysqli_error());
if (mysqli_num_rows($check)>=1)
{
echo "return_msg=Username_already_taken";}
else
{
//register into database
mysqli_query($con,"INSERT INTO Test (username,password,email) VALUES
('$username','$password','$email');") or die(mysqli_error());
}
echo "return_msg=success" ;
}
}
?>
非常感谢您的时间和帮助