您的代码中存在一些问题:
动作脚本 2:
使用发送数据LoadVars http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00001161.html对象,您必须将其作为其属性附加到该对象,如果您想从服务器端脚本接收响应,您可以使用LoadVars.sendAndLoad() http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00001174.html但如果您只想发送该数据而不等待任何响应,您可以使用LoadVars.send() http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00001173.html.
假设你会使用sendAndLoad()
函数,所以你的代码可以是这样的:
var url:String = 'http://www.example.com/update.php';
// the LoadVars object that will receive (load) a response from the server
var receiver:LoadVars = new LoadVars();
receiver.onLoad = function(success:Boolean)
{
if (success) {
trace(receiver.response); // gives for example : update successful
} else {
trace('error');
}
}
// the LoadVars object which will send (post) some data to the server
var sender:LoadVars = new LoadVars();
sender.id = txt_id.text;
sender.name = txt_name.text;
sender.sendAndLoad(url, receiver); // we don't set the method to POST because that's its default value
PHP :
正如许多评论中提到的,PHPisset() http://php.net/manual/en/function.isset.php函数用于验证变量是否已设置且不为 NULL,并返回一个布尔值(TRUE
of FALSE
)这就是当它转换(转换)为字符串 http://php.net/manual/en/language.types.string.php#language.types.string.casting会给你1
for TRUE
和 `` (空字符串)FALSE
.
就你的情况而言,根据你的说法,我认为作为变量$_POST['OutData']
显然已设定,isset($_POST['OutData'])
为 true 时将设置$isi
to 1
,所以你会得到:
$query2 = "UPDATE materi SET isi='1' WHERE id = 1";
但根据您发布的代码,我认为您应该得到:
$query2 = "UPDATE materi SET isi='' WHERE id = 1";
现在回到我们当前的示例,我们将获取 AS2 脚本发送的两个 POST 变量(id 和 name)来更新数据库,然后返回数据是否已成功更新的响应:
<?php
if(isset($_POST['id'] && isset($_POST['name']))
{
$id = $_POST['id'];
$name = $_POST['name'];
mysql_pconnect('localhost', 'root', '');
mysql_select_db('my_db');
$query = "UPDATE users SET name = '$name' WHERE id = $id";
$result = mysql_query($query);
if($result){
echo 'response=update successful';
} else {
echo 'response=update failed';
}
}
?>
当然,在这里我只是试图根据您当前的代码为您提供一个非常简单的工作代码示例。您应该知道,对于您的 PHP 端,“mysql”扩展在 PHP 5.5.0 中已被弃用,并在 PHP 7 中被删除,因此您应该考虑使用"mysqli" http://php.net/manual/en/book.mysqli.php or "PDO" http://php.net/manual/en/ref.pdo-mysql.php扩展,有关更多信息,请查看here http://php.net/manual/en/mysqlinfo.api.choosing.php,也不要忘记sanitize http://php.net/manual/en/filter.filters.validate.php, validate http://php.net/manual/en/filter.filters.validate.php and escape http://php.net/manual/en/mysqli.real-escape-string.php任何用户的数据,...对于 ActionScript 方面,也许是时候开始了学习 ActionScript 3 http://www.adobe.com/devnet/actionscript/learning.html ...
希望能有所帮助。