inserting value into database using post method not working - php

i want to update my database table newlessontime by posting a value from as3.but query is not working ...but when i give $etime = 4 in php code then database is updating lesson1 column but but when it comes for post method, value is not inserting into lesson1 column why is this happening? stdroll column value was inserted already i want to update lesson1 in same row of the table
here is my php file
// lesson1t.php
include('connect.php');
$etime = $_POST['time1'];
//$etime = 4;
if (mysqli_query($link, "UPDATE newlessontime set lesson1=$etime WHERE stdroll=123")) {
echo 'result=System Updated';
} else {
echo 'result=error';
}
mysqli_close($link);
?>
here is the fla file
home_Btn.buttonMode = true;
home_Btn.addEventListener(MouseEvent.CLICK, indexBtn_click1);
function indexBtn_click1(event:MouseEvent):void
{
myTime.stop();
variables.time1 = my_time.text ;
var request:URLRequest = new URLRequest('http://localhost/lesson1t.php');
request.method = URLRequestMethod.POST;
request.data = variables;
var loader:URLLoader = new URLLoader(request);
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.load(request);
loader.addEventListener(Event.COMPLETE, dataOnLoadl);
function dataOnLoadl(event:Event)
{
var variables:URLVariables = URLVariables(event.target.data);
trace(variables.result); // gives : System Updated
}
gotoAndPlay("manu");
SoundMixer.stopAll();
}

Maybe you problem is that you do not defined variable.time1 as a var in as3.
Try this...
home_Btn.buttonMode = true;
home_Btn.addEventListener(MouseEvent.CLICK, indexBtn_click1);
function indexBtn_click1(event:MouseEvent):void
{
myTime.stop();
var request:URLRequest = new URLRequest('http://localhost/lesson1t.php');
request.method = URLRequestMethod.POST;
//You should define what is variables...
var variables:URLVariables = new URLVariables(); //this you forgot!
variables.time1 = my_time.text ;
request.data = variables;
var loader:URLLoader = new URLLoader(request);
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.load(request);
loader.addEventListener(Event.COMPLETE, dataOnLoadl);
function dataOnLoadl(event:Event)
{
var variables:URLVariables = URLVariables(event.target.data);
trace(variables.result); // gives : System Updated
}
gotoAndPlay("manu");
SoundMixer.stopAll();
}
Try this and tell us what happen...

I forgot to give quote around $etime.
It should be '$etime' ..Now its working

Related

want to insert timer class time in database as3

i want to insert timer time in my database.i have created a timer class which is increasing in miniutes and seconds (in a dynamic text field).i have a home_button i want that when i click home_button timer time would be inserted into time column of scoreu table.all code is working fine.column is updating but time is not showing up in database table please help me to solve this..here is my as3 code
var myCount:Number = 00;
var seconds:Number = 00;
var minutes:Number = 0;
var myTime:Timer = new Timer(1000,myCount);
myTime.addEventListener(TimerEvent.TIMER, startCount);
my_time.text = "";
myTime.start();
function startCount(event:TimerEvent):void
{
seconds +=1;
if (seconds > 60)
{
seconds =00;
minutes +=1;
}
my_time.text = minutes+":"+(seconds >= 10 ? seconds : "0"+seconds);
}
var variables:URLVariables = new URLVariables();
variables.time1 = my_time.text;
home_Btn.buttonMode = true;
home_Btn.addEventListener(MouseEvent.CLICK, indexBtn_click1);
function indexBtn_click1(event:MouseEvent):void
{
myTime.stop();
var request:URLRequest = new URLRequest('http://localhost/timesend.php');
request.method = URLRequestMethod.POST;
request.data = variables;
var loader:URLLoader = new URLLoader(request);
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.load(request);
loader.addEventListener(Event.COMPLETE, dataOnLoad);
}
function dataOnLoad(event:Event)
{
var variables:URLVariables = URLVariables(event.target.data);
trace(variables.result); // gives : System Updated
}
here is timesend.php
<?php
// data.php
include('connect1.php');
// if we are here, that's mean that we are already connected to mysql server
// and we don't need to do another connection
$etime = $_POST['time1'];
// $link is the same connection created in your connect.php script
if (mysqli_query($link, "INSERT INTO scoreu (user) VALUES('$etime')")) {
echo 'result=System Updated';
} else {
echo 'result=error';
}
mysqli_close($link);
?>
there was a problem in table field type declaration ..i declared it as varchar..but now i have fixed the type as TEXT..now it is working perfect..

how to communicate actionscript3.0 with php?

i am trying to send the data from actionscript to php file.but am not able to communicate with php file.am getting error like this "Undefined index: username in C:\xampp\htdocs\As\basics.php on line 2".
my code is below.
/*********actionscript******************/
var str:String = "hi";
var myscore = 0;
submit.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_7);
function fl_ClickToGoToAndStopAtFrame_7(event: MouseEvent): void {
var myrequest:URLRequest = new URLRequest("http://localhost/As/basics.php");
myrequest.method = URLRequestMethod.POST;
var variables:URLVariables = new URLVariables();
variables.username = str;
variables.score = myscore;
myrequest.data = variables;
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.addEventListener(Event.COMPLETE, dataOnLoad);
loader.load(myrequest);
}
function dataOnLoad(evt:Event)
{
submit.alpha=100;
//status is a custom flag passed from back-end
}
/*********php code**********************/
<?php
$name = $_POST['username'];
echo "Result:<input type='text' value='$name'>";
echo "<param name='movie' value='cmphp.swf' />";
echo "<object type='application/x-shockwave-flash' data='cmphp.swf'width='1024' height='500'>";
echo "<param name='movie' value='FlashVars_AS2.swf' />";
?>

How can you send an array of numbers from as3 to php?

Here's what I'm working with:
var stats:Array = ["11", "22", "33"];
create();
function create():void
{
var sender:URLLoader = new URLLoader;
var myVar:URLVariables = new URLVariables;
myVar.stats = stats;
var website:URLRequest = new URLRequest("http://www.roomrecess.com/MQFiles/createChar.php");
website.data = myVar;
sender.load(website);
sender.addEventListener(Event.COMPLETE, sendComplete);
}
You can also email me at: brian.king#southmont.12.in.us
thanks!!!!
Should be pretty self explanatory.
var vars = new URLVariables();
vars.postFieldName1="dummy1";
vars.postFieldNameA="dummy2";
var req:URLRequest = new URLRequest("entry.php");
req.method = URLRequestMethod.POST;
req.data = vars;
var sender=new URLLoader();
sender.addEventListener(Event.COMPLETE, dataSent);
sender.dataFormat = URLLoaderDataFormat.BINARY;
sender.load(req);

Get variables fom a txtor php file

I have this code on .fla file
fm_button.visible = false;
var menu_label:Array = new Array("Introduction", "Products", "Services",
"Testimonials", "Our Company", "Contact Us");
var total:Number = menu_label.length;
var i:Number = 0;
var page:Number;
var main_menu:MovieClip = new MovieClip();
stage.addChild(main_menu);
for (i = 0; i < total; i++)
{
var btn = new flashmo_button();
btn.name = "btn" + i;
btn.x = fm_button.x;
btn.y = fm_button.y + i * ( fm_button.height + 10 );
btn.buttonMode = true;
btn.item_no = i;
btn.flashmo_click_area.addEventListener( Event.ENTER_FRAME, btn_enter );
var each_substring:Array = menu_label[i].split("|");
btn.flashmo_button_label.fm_label.text = each_substring[0];
btn.item_url = each_substring[1];
main_menu.addChild(btn);
}
function btn_over(e:MouseEvent):void
{
e.target.parent.over = true;
}
function btn_out(e:MouseEvent):void
{
e.target.parent.over = false;
}
What i want is to get this values:
("Introduction", "Products", "Services", "Testimonials", "Our
Company", "Contact Us");
from a text or php file named menu.php or menu.txt
Is this possible?
Why you need read from .php file?
Is this client-server communication?
In that case, when .fla file loads by client browser over http(s) you should do something like this:
menu.php (for example put this file to document root folder):
<?php $menu = array('Elem1', 'Elem2');
echo json_encode($menu); ?>
.fla:
var sendData:URLVariables = new URLVariables();
var request:URLRequest = new URLRequest('/menu.php');
request.method = URLRequestMethod.GET;
var loader:URLLoader = new URLLoader(request);
loader.addEventListener(Event.COMPLETE, onCompleted);
So, your .fla are doing query to server and get's list of categories (onCompleted method receive data).
If this is not server-client communication, you should use other file format, because .php is not a data storage )

using nested arrays by php http_build_query() and recieve them in flash AS3

i am having this hard time figuring what is needed to do,
i am using URLVariables to send/recieve values between flash and PHP
the problem is, i am unable to access nested arrays ( array inside an array ) with flash
heres an example:
$dgresult = array("total" => $results);
echo http_build_query($dgresult,"flf_");
in flash, all i need to do is to use:
var variables:URLVariables = new URLVariables(e.target.data);
then i can access it with :
variables.total
the problem now is when i have nested arrays:
$dgresult = array("total" => $results);
array_push($dgresult,$another_array);
http_build_query($dgresult,"flf_");
i can still access variables.total
but what about anything that has flf_ ?
how is that possible?
you should try to simply use established formats for complex data, such as JSON. For PHP see here and for AS3 see here. Or ready made solutions such as AMFPHP.
greetz
back2dos
or you can just parse the object
var url:String = 'http://localhost/dump.php';
var params:Object = {
test: 'ok',
nested_1: {
nested_2: {
nested_3: {
nested_4: {
hello: 'mf',
str: '~!##$%^&*()_+'
}
}
}
},
};
var request:URLRequest = new URLRequest(url);
var variables:URLVariables = new URLVariables();
parameters = fixParameters(parameters || {});
for (var key:String in parameters) {
variables[key] = parameters[key];
}
request.data = variables;
var loader:URLLoader = new URLLoader();
loader.load(request);
and here is fixParameters method
private function fixParameters(data:Object, parameters:Object = null, prefixes:Array = null):Object {
var setPrefix:Array;
var prefixKey:String;
if (!parameters) {
parameters = {};
}
if (!prefixes) {
prefixes = [];
}
for (var key:String in data) {
setPrefix = prefixes.concat([key]);
if (typeof(data[key]) == 'object') {
parameters = fixParameters(data[key], parameters, setPrefix);
} else {
prefixKey = '';
for (var i:Number = 0; i < setPrefix.length; i++) {
prefixKey += i == 0 ? setPrefix[i] : '[' + setPrefix[i] + ']';
}
parameters[prefixKey] = data[key];
}
}
return parameters;
}

Categories