I want to update database with flash (text input)
Here is my php code
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 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 :
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.