本文介绍了结果从Flash更新数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我想使用flash更新数据库(文本输入) 这是我的php代码 <?php mysql_pconnect(localhost,root,); mysql_select_db(adaptasi); $ isi = isset($ _ POST ['OutData']); $ query2 =更新materi SET isi ='$ isi'WHERE id = 1; $ result2 = mysql_query($ query2)or die(Query Failed:.mysql_error()); ?> 这是我的Actionscript 2 { trace(Sending); var OutData = new LoadVars(); text_morfologi.text = OutData.OutData; filepath =http:// localhost / adaptasi /; OutData.sendAndLoad(filepath +editmorfologi.php,OutData,POST); $ b btnsave.onRelease = function() { SubmitData(); btnedit.visible = true; btnsave.visible = false; }; 但是数据库中的结果是'1',而不是我在文本字段中输入的文本。 谢谢 解决方案在代码中有一些问题: 使用 AS2LCR / Flash_10.0 / help.html?content = 00001161.htmlrel =nofollow> LoadVars 对象,您必须将其附加到该对象它的属性,如果你想从你的服务器端脚本收到响应,你可以使用 LoadVars.sendAndLoad() ,但是如果您只想发送该数据而不等待任何响应,则可以使用 LoadVars.send() 。 假设您将使用 sendAndLoad()函数,你的代码可以是这样的: var url:String ='http:// w ww.example.com/update.php; //将从服务器接收(加载)响应的LoadVars对象 var receiver:LoadVars = new LoadVars(); receiver.onLoad = function(success:Boolean) { if(success){ trace(receiver.response); //例如:更新成功} else { trace('error'); //发送(发布)一些数据到服务器的LoadVars对象 var sender:LoadVars = new LoadVars(); sender.id = txt_id.text; sender.name = txt_name.text; sender.sendAndLoad(url,receiver); //我们不设置方法为POST,因为这是它的默认值 PHP:正如很多评论中提到的那样,PHP的 $ c> TRUE FALSE ),这是将给你 1 for TRUE 和 FALSE 的空字符串。 在你的情况,根据你,我认为作为变量 $ _ POST ['OutData'] 显然设置, isset($ _POST ['OutData'])是真的,它会将 $ isi 的值设置为 1 $ query2 =UPD ATE materi SET isi ='1'WHERE id = 1; 但根据您的发布代码,我认为您应该获得: $ query2 =更新materi SET isi =''WHERE id = 1; 现在回到我们当前的例子,我们将得到两个POST变量(id和name)通过AS2脚本更新数据库,然后返回一个响应,如果数据已经成功更新或不是: < php $ b $ if(isset($ _ POST ['id']&& isset($ _ POST ['name'])) { $ id = $ _POST [ 'id']; $ name = $ _POST ['name']; $ b $ 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'; } } $ b $> 当然这里我只是试图给你一个非常简单的e根据您当前的工作代码的xample。您应该知道,对于您的PHP端来说,mysql扩展名在PHP 5.5.0中被弃用,并且在PHP 7中被删除了,所以您应该考虑使用mysqli或PDO扩展,更多关于这个,看看这里,也不要忘了消毒, href =http://php.net/manual/en/filter.filters.validate.php =nofollow> validate and 转义任何用户的数据,...对于ActionScript方面,也许是时候开始学习ActionScript 3 ... 希望可以帮助。 I want to update database with flash (text input)Here is my php code<?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());?>Here is my Actionscript 2function 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;};But the result isi in database is '1' not the text that I input in the text field.Thanks 解决方案 You have some problems in your code :ActionScript 2 :To send data using a 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().Supposed that you will use sendAndLoad() function, so you code can be like this : var url:String = 'http://www.example.com/update.php';// the LoadVars object that will receive (load) a response from the servervar 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 servervar 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 valuePHP :As mentioned in many comments, the PHP's 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 will give you 1 for TRUE and `` (empty string) for FALSE.In your case, and according to you, I think that as the the variable $_POST['OutData'] is apparently set, isset($_POST['OutData']) is true which will set the value of $isi to 1, so you will get : $query2 = "UPDATE materi SET isi='1' WHERE id = 1";but according to your posted code, I think that you should get :$query2 = "UPDATE materi SET isi='' WHERE id = 1";Returning now to our current example, we will get our two POST variables (id, and name) sent by the AS2 script to update the DB and then return a response if the data has been successfully updated or not : <?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'; } }?>Of course here I tried just to give you a very simple example of a working code according to your current one. You should know that for your PHP side that the "mysql" extension was deprecated in PHP 5.5.0 and was removed in PHP 7, so you should think to use "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 ...Hope that can help. 这篇关于结果从Flash更新数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-24 18:31