0

我正在我的网站上使用两个输入框和一个提交按钮处理 Flash 内容。用户应填写方框(学校和学生)并提交。数据库表是一个自动增量列和每个变量的列。问题是在提交和发送值时,表会增加 2 行具有相同值的行。这是我的代码:

import flash.events.Event;
import flash.net.URLRequest;

validate_btn.addEventListener (MouseEvent.CLICK, Validate);

function Validate (e:Event)     {
var Variables:URLVariables = new URLVariables();
var Request:URLRequest = new URLRequest("participant.php");
var Loader:URLLoader = new URLLoader();

Variables.school = escape(school_txt.text);
Variables.student = escape(student_txt.text);
Request.method = URLRequestMethod.POST;
Request.data = Variables;
Loader.dataFormat = URLLoaderDataFormat.VARIABLES;
Loader.addEventListener(Event.COMPLETE, Complete);
Loader.load(Request);

navigateToURL(Request, "participant.php");
}

function Complete(e:Event) {
ntext = unescape(e.target.data.x);
gotoAndStop(2);
}

<?php
$school = urldecode($_POST['school']);
$student = urldecode($_POST['student']);
$flag = 0;

$connection = mysql_connect("localhost","root","");
if (!$connection) {
die (mysql_error());
}

$db_select = mysql_select_db("db_school", $connection);
if (!$db_select) {
die(mysql_error());
}

mysql_query("INSERT INTO School (school, student, flag)
VALUES ('$school','$student','$flag')") 
or die(mysql_error());

if(isset($connection)) {
mysql_close($connection);
}

echo "x=participation successfully record";
?>

那么它有什么问题呢?

4

1 回答 1

0

在您的代码中,您有两个命令,它们都做同样的事情:

Loader.load(Request);

navigateToURL(Request, "participant.php");

所以你只需要使用其中之一。要在您的 Complete() 函数中获得适当的响应,请使用第一个。

我试过自己做。它适用于两个命令!(第二个命令不会在 Flex 中引起反应,因为它不应该这样做)。

于 2013-06-16T09:16:39.883 回答