结果从闪存更新数据库
Result Update Database from Flash
我想用 flash 更新数据库(文本输入)
这是我的 php 代码
<?php
mysql_pconnect ("localhost", "root", "");
mysql_select_db ("adaptasi");
$isi = isset($_POST['OutData']);
$query2 = "UPDATE materi SET isi='$isi' WHERE id = 1";
$result2=mysql_query($query2) or die("Query Failed : ".mysql_error());
?>
这是我的 Actionscript 2
function SubmitData()
{
trace("Sending");
var OutData = new LoadVars();
text_morfologi.text = OutData.OutData;
filepath = "http://localhost/adaptasi/";
OutData.sendAndLoad(filepath + "editmorfologi.php", OutData, "POST");
}
btnsave.onRelease = function()
{
SubmitData();
btnedit.visible = true;
btnsave.visible = false;
};
但是数据库中的结果是“1”,而不是我在文本字段中输入的文本。
谢谢
您的代码有一些问题:
动作脚本 2 :
使用LoadVars
object you have to attache it to that object as its properties, and if you want to receive a response from your server side script, you can use LoadVars.sendAndLoad()
but if you want just to send that data without waiting for any response, you can use LoadVars.send()
发送数据。
假设你要使用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 :
如许多评论中所述,PHP 的 isset()
function is used to verify if a variable is set and is not NULL and it returns a boolean value ( TRUE
of FALSE
) which is when it's casting (converting) to a string 将为 TRUE
提供 1
,为 [=20= 提供 ``(空字符串) ].
在你的情况下,根据你的说法,我认为显然设置了变量 $_POST['OutData']
,isset($_POST['OutData'])
为真,这会将 $isi
的值设置为 1
,所以你会得到:
$query2 = "UPDATE materi SET isi='1' WHERE id = 1";
但根据您发布的代码,我认为您应该得到:
$query2 = "UPDATE materi SET isi='' WHERE id = 1";
现在回到我们当前的示例,我们将获得 AS2 脚本发送的两个 POST 变量(id 和名称)以更新数据库,然后 return 响应如果数据是否已成功更新:
<?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" or "PDO" extensions, for more about that, take a look here, also don't forget to sanitize, validate and escape any user's data, ... and for the ActionScript side, maybe it's the time to start learning ActionScript 3 ...
希望能帮到你。
我想用 flash 更新数据库(文本输入)
这是我的 php 代码
<?php
mysql_pconnect ("localhost", "root", "");
mysql_select_db ("adaptasi");
$isi = isset($_POST['OutData']);
$query2 = "UPDATE materi SET isi='$isi' WHERE id = 1";
$result2=mysql_query($query2) or die("Query Failed : ".mysql_error());
?>
这是我的 Actionscript 2
function SubmitData()
{
trace("Sending");
var OutData = new LoadVars();
text_morfologi.text = OutData.OutData;
filepath = "http://localhost/adaptasi/";
OutData.sendAndLoad(filepath + "editmorfologi.php", OutData, "POST");
}
btnsave.onRelease = function()
{
SubmitData();
btnedit.visible = true;
btnsave.visible = false;
};
但是数据库中的结果是“1”,而不是我在文本字段中输入的文本。 谢谢
您的代码有一些问题:
动作脚本 2 :
使用LoadVars
object you have to attache it to that object as its properties, and if you want to receive a response from your server side script, you can use LoadVars.sendAndLoad()
but if you want just to send that data without waiting for any response, you can use LoadVars.send()
发送数据。
假设你要使用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 :
如许多评论中所述,PHP 的 isset()
function is used to verify if a variable is set and is not NULL and it returns a boolean value ( TRUE
of FALSE
) which is when it's casting (converting) to a string 将为 TRUE
提供 1
,为 [=20= 提供 ``(空字符串) ].
在你的情况下,根据你的说法,我认为显然设置了变量 $_POST['OutData']
,isset($_POST['OutData'])
为真,这会将 $isi
的值设置为 1
,所以你会得到:
$query2 = "UPDATE materi SET isi='1' WHERE id = 1";
但根据您发布的代码,我认为您应该得到:
$query2 = "UPDATE materi SET isi='' WHERE id = 1";
现在回到我们当前的示例,我们将获得 AS2 脚本发送的两个 POST 变量(id 和名称)以更新数据库,然后 return 响应如果数据是否已成功更新:
<?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" or "PDO" extensions, for more about that, take a look here, also don't forget to sanitize, validate and escape any user's data, ... and for the ActionScript side, maybe it's the time to start learning ActionScript 3 ...
希望能帮到你。