Question

Updating dynamic data in flash (mySQL/PHP)

Asked by: sam928

Hello,
I have a flash application that loads data from mySQL dynamically.

I am using AS2 and loadVars.
Everything loads great into my dynamic text fields, but the question is, How do I take it one step further and be able to Update the data and send it back to the database?

I have a PHP script for starters, so I just need to figure out the ActionScript... I know that ultimately this is called 'Updating dynamic data'      ---- but am yet to find somebody that actually knows how to do it.

anybody know where to start?

--------------------
heres what i have so far.

mySQL -- with 4 fields (id, name, details, other)

PHP script - posted below (dont know if it is the correct code?)

ActionScript -- that loads data using loadVars (but this is only to load the data in.. and display it)

----obviously the next step is to create input fields and a Submit button.

what actionscript do i use?
Do I load data in as a string, or break it down, parse it? what?


----------------------
;)))))))

<?php
$connect = mysql_connect("db1603.perfora.net", "dbo254844067", "Q77hasTT");
mysql_select_db("db254844067", $connect);
 
 
   //Capture data from $_POST array
   $id = $_POST['id'];
   $name_txt = $_POST['name_txt'];
   $details_txt = $_POST['details_txt'];
   $price_txt = $_POST['price_txt'];
   
   	$id = mysql_real_escape_string('$id');
    $name_txt = mysql_real_escape_string('$name_txt');
	$details_txt = mysql_real_escape_string('$details_txt');
	$price_txt = mysql_real_escape_string('$price_txt');
   
 
   $result = "UPDATE loadcms set name_txt = '$name_txt', details_txt = '$details_txt', price_txt = '$price_txt' where id = '$id'";
   
   if($result) echo "writing=Ok&";
   else echo "writing=Error";
?>

                                  
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:

Select allOpen in new window

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-09-20 at 20:41:10ID24747412
Tags

flash

,

cms

,

actionscript

,

as2

,

php

Topics

ActionScript

,

PHP Scripting Language

Participating Experts
2
Points
500
Comments
40

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. LoadVars() question
    Hello, How can I LoadVars() from a php page ? What kind of format do I need to output from php ? I have a mysql database, and I will use PHP to send query result to Flash movie. Basically I need to retrieve some value pair, USERNAME and SCORE from that database. User1=scor...
  2. MySQL & PHP
    Experts, I just installed MySQL and PHP5 on Windows Server 2003. How do I configure PHP to interface with MySql?
  3. trouble shooting when not all POST variables are being load…
    I am sending data from a Flash .swf to a .php file. Some of the properties of the flash LoadVars object are not loading with the $_POST['propertyName'] array. I know that the data from $_POST['propertyName'] is not loading because when I check my Mysql data base, the data is...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: sam928Posted on 2009-09-20 at 20:44:23ID: 25380188

continuation....... I understand the concept of 'Saving/Sending data' to the database...i have this already structured,,, it is where I add a new record to the database... BUT it does NOT allow me to update an entry.


That is my question, how do i select an entry from the database and update it?


 

by: crooksy88Posted on 2009-09-21 at 00:05:36ID: 25380712

Actionscript. You need to be using sendAndLoad to send data back to the database.

PHP. You must first find, or select the row from the database...

//get info from database
$select = "SELECT * FROM `tableName` WHERE `id` = '$id'";

$result = mysql_query($select) or die(mysql_error());

//how many rows were found?
$numresults = mysql_num_rows($result);

//if no rows were found do this
if($numresults==0) {

} else {

//else if a row was found, update it
$update = "UPDATE `tableName` SET `name_txt`='$name_txt' WHERE `id` = '$id'";
mysql_query($update) or die(mysql_error());

 

by: andoneknightPosted on 2009-09-21 at 04:07:26ID: 25381681

Sending/Receiving variables through flash/PHP is a relatively simple affair:

1) User writes variables into input fields
2) Send data to PHP script
3) send info like normal to MySQL

The below Actionscript is used to send data from input fields in your flash to PHP. PHP then returns values, in this case the variable called "varName". Obviously you can change this script so that you can just load the php page and then run the script on that to select the MySQL data and send that back to the Flash program(just ignore the initial variables).

If you want to continually send variables back and forth then just setup some functions which are run when user clicks on, e.g. update, select, delete buttons etc!

//Actionscript
 
var variables:URLVariables = new URLVariables();
var conPage:String="http://www.DOMAINNAME.co.uk/contact.php"; //change to your PHP script
var varSend:URLRequest=new URLRequest(conPage);
varSend.method=URLRequestMethod.POST; //Method of sending data
varSend.data=variables; //Name of your variables acontainer
var varLoader:URLLoader=new URLLoader();//Load the URLLoader
varLoader.dataFormat=URLLoaderDataFormat.VARIABLES;
 
//Set all of the variables you want to send to PHP-------------------------------
variables.id=this.contact_id.input_txt.text;//These are obviously textfields
variables.name=this.contact_name.input_txt.text;
variables.details=this.contact_details.input_txt.text;
variables.price=this.contact_price.input_txt.text;
 
variables.sendRequest="parse";
varLoader.addEventListener(Event.COMPLETE, pageLoaded);
varLoader.load(varSend);//Load the PHP page/variables and once its loaded perform the function "pageLoaded"
 
function pageLoaded(e:Event):void {
          var strName:String=e.target.data.varName;//This targets the information received back from the PHP script for a variable called "varName"
          //Do whatever you want with the information you get back from the PHP script.
}
 
 
//PHP---------------------------------(As per Crooksy's comment above)
 
In PHP grab the variables from the flash file (If you had any in the first place):
     $personsname = $_POST['name']; //(Don't forget our method was POST and so this is how PHP will read the variables)
 
//get info from database
$select = "SELECT * FROM `tableName` WHERE `id` = '$id'";
 
$result = mysql_query($select) or die(mysql_error());
 
//how many rows were found?
$numresults = mysql_affected_rows($result);
 
//if no rows were found do this
if($numresults==0) {
 
} else {
 
//else if a row was found, update it
$update = "UPDATE `tableName` SET `name_txt`='$name_txt' WHERE `id` = '$id'";
mysql_query($update) or die(mysql_error());

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:

Select allOpen in new window

 

by: sam928Posted on 2009-09-21 at 23:16:11ID: 25389966

hello crooksy88 & andoneknight, thank you for the fast response.

I was wondering if you can translate that actionscript to a loadVars format?

---------------------
i load/display all my data from mySQL using loadVars currently with the following code in snippet below.


So can we incorporate my existing code with the 'Update' code?  (loadVars)?

here is a preview of the file and how it loads the data
http://previewsample.com/loaddatacms




myData = new LoadVars();
 
myData.load("http://previewsample.com/loaddatacms/loadcms.php");
myData.ref = this;
 
//Fetch data 
myData.onLoad = function(succes)
{
	if (succes)
	{
		for (var i:Number = 0 ; i < parseInt(this.cant) ; i++)
		{
			this.ref["mc" + i].id.htmlText = "" + this["id" + i] + "";
			this.ref["mc" + i].name_txt.htmlText = "" + this["name_txt" + i] + "";
			this.ref["mc" + i].details_txt.htmlText = "" + this["details_txt" + i] + "";
			this.ref["mc" + i].price_txt.htmlText = "" + this["price_txt" + i] + "";
			
			
			
		}
	}
	else
	{
		trace("Error loading data");
	}
};
stop();

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:

Select allOpen in new window

 

by: crooksy88Posted on 2009-09-22 at 00:11:56ID: 25390243

I think there is a little confusion here.
LoadVars is an object that stores vars that are received from a specified url.
LoadVars by itself cannot send data to a php script that then updates a database.

You need to break down the procedure as follows:

1. Gather data in flash and send it to the PHP script (using sendAndLoad();)

2. PHP collects the data and updates a database, then sends data back to Flash.

3. LoadVars collects this data and you do something with it.

 

by: crooksy88Posted on 2009-09-22 at 00:22:00ID: 25390286

This is what a typical sendAndLoad might look like

var sendData:LoadVars = new LoadVars();
var loadData:LoadVars = new LoadVars();
 
//add the vars to the sendData object
sendData.name_Txt = "Peter";
sendData.var_2 = "var2"
 
//send vars to the php script and pass the return data to loadData
sendData.sendAndLoad("http://www.domain.com/script.php", loadData, "POST");
 
//when loadData actually loads the data that is returned, run the whatToDo function
loadData.onLoad = whatToDo;  
}
 
function whatToDo(success:Boolean) { 
if (success) {
 
trace("LOADDATA RECEIVED: "+loadData);
	
} else {
trace("ERROR");
}
}
}

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:

Select allOpen in new window

 

by: sam928Posted on 2009-09-22 at 12:26:34ID: 25396521

hello,
sorry your code threw me off with all of the URLRequest and URLLoader variables.
----------------------------------
Using your actionscript. i have 4 compiler errors.....
here is the .fla ,, if you wish, to view what the heck is going on.. ;))
http://previewsample.com/loadupdate/loadupdate.fla

----------------
also , in the PHP there was an error when i tested in the browser,, it reads the following:
Parse error:  syntax error, unexpected $end in /homepages/34/d229401770/htdocs/111Privet/LoadUpdate/update.php on line 32


view here.  (PHP code is in snippet below)
http://previewsample.com/loadupdate/update.php
------------------------------------------------------------------------------

is there any way we can go with the simplfied version of actionscript  that you posted in your last message? (you lost me on all the URLrequest's and URLloader things.. )   <<<<< sorry if i come across as a doofas.. i am just learning all of this. ;)))

<?php
$connect = mysql_connect("db1603.perfora.net", "dbo254844067", "Q77hasTT");
mysql_select_db("db254844067", $connect);
 
 
 
//PHP---------------------------------(As per Crooksy's comment above)
 
//In PHP grab the variables from the flash file (If you had any in the first place):
     $name_txt = $_POST['name_txt']; //(Don't forget our method was POST and so this is how PHP will read the variables)
 	$details_txt = $_POST['details_txt'];
 	$price_txt = $_POST['price_txt'];
 
 
//get info from database
$select = "SELECT * FROM loadtest WHERE `id` = '$id'";
 
$result = mysql_query($select) or die(mysql_error());
 
//how many rows were found?
$numresults = mysql_affected_rows($result);
 
//if no rows were found do this
if($numresults==0) {
 
} else {
 
//else if a row was found, update it
$update = "UPDATE loadtest SET `price_txt`='$price _txt' WHERE `id` = '$id'";
mysql_query($update) or die(mysql_error());
 
?>

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:

Select allOpen in new window

 

by: crooksy88Posted on 2009-09-22 at 14:11:31ID: 25397665

FYI andoneknight's code is AS3.

In your PHP file you are looking for $id but you have not specified a variable named $id.

 

by: sam928Posted on 2009-09-22 at 15:24:01ID: 25398151

@crooksy88..

thanks for pointing that out.. i though i stated that i was using AS2 at the beginning..

soo. then we can use your version: (attached below on snippet..)
but i still get a compiler error for "unexpected '}' on line 14"

i tried to remove it and then it gives me 3 other compiler errors.  how can that be fixed?

-----------------------------------
on the PHP, i have added the variable $id,,, but it still has that error.
http://previewsample.com/loadupdate/update.php

------------------------------
so we have one flash compiler error and one error on the PHP.      is there some kind of program to fix these? or is it just trouble shooting? but i have no idea hot to fix it..i've tried removing that 'unexpected }' but then it gave me more compiler errors.


var sendData:LoadVars = new LoadVars();
var loadData:LoadVars = new LoadVars();
 
//add the vars to the sendData object
sendData.name_xt = "name_txt";
sendData.details_txt = "details_txt"
sendData.price_txt = "price_txt"
 
//send vars to the php script and pass the return data to loadData
sendData.sendAndLoad("http://www.previewsample.com/loadupdate/update.php", loadData, "POST");
 
//when loadData actually loads the data that is returned, run the whatToDo function
loadData.onLoad = whatToDo;  
}
 
function whatToDo(success:Boolean) { 
if (success) {
 
trace("LOADDATA RECEIVED: "+loadData);
        
} else {
trace("ERROR");
}
}
}

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:

Select allOpen in new window

 

by: sam928Posted on 2009-09-22 at 15:26:21ID: 25398167

do i need to add the id variable in the actionscript to?    or is that just for referencing the record we are targeting?

 

by: crooksy88Posted on 2009-09-22 at 23:34:21ID: 25400483

Flash:

When you have issues with curly braces it's a good idea to comment them so you can see which is doing what.

var sendData:LoadVars = new LoadVars();
var loadData:LoadVars = new LoadVars();
 
//add the vars to the sendData object
sendData.name_xt = "name_txt";
sendData.details_txt = "details_txt"
sendData.price_txt = "price_txt"
 
//send vars to the php script and pass the return data to loadData
sendData.sendAndLoad("http://www.previewsample.com/loadupdate/update.php", loadData, "POST");
 
//when loadData actually loads the data that is returned, run the whatToDo function
loadData.onLoad = whatToDo;  
 
function whatToDo(success:Boolean) { 
if (success) {
trace("LOADDATA RECEIVED: "+loadData);      
} //close if
 
else {
trace("ERROR");
 
}//close else
}// close function
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:

Select allOpen in new window

 

by: crooksy88Posted on 2009-09-22 at 23:43:46ID: 25400518

PHP

Try 'reading through' your PHP to follow what it is trying to do...

<?php
//connect to database
$connect = mysql_connect("db1603.perfora.net", "dbo254844067", "Q77hasTT");
mysql_select_db("db254844067", $connect);
 
//get variables from the flash post
$name_txt = $_POST['name_txt'];
$details_txt = $_POST['details_txt'];
$price_txt = $_POST['price_txt'];
 
 
//get info from database
//select all from the table loadtest where column 'id' equals the variable $'id'
$select = "SELECT * FROM loadtest WHERE `id` = '$id'";

//(NOTE The problem here is that php hasn't been told about a variable named $id yet)

//This query should reflect the variables you have and the table columns you have
// e.g. $select = "SELECT * FROM loadtest WHERE `name_txt` = '$name_txt";
//This assumes you have a column in your table called name_txt
 
$result = mysql_query($select) or die(mysql_error());
 
//how many rows were found?
//NOTE. Just pointing out this is different to my code above
$numresults = mysql_affected_rows($result);
 
//if no rows were found do this
if($numresults==0) {
 
} else {
 
//else if a row was found, update it
//NOTE again you are using the $id variable here which hasn't been defined.

$update = "UPDATE loadtest SET `price_txt`='$price _txt' WHERE `id` = '$id'";
mysql_query($update) or die(mysql_error());
 
?>

 

by: sam928Posted on 2009-09-23 at 07:55:45ID: 25403825

thank you for that information crooksy88..

the flash is compiling with no errors..
-------------------------------------------------------
so what you were explaining about the id variable,  I have added this line below:

//get variables from the flash post
$id = $_POST['id'];   // I ADDED THIS LINE... IS THIS WHAT YOU MEAN?
$name_txt = $_POST['name_txt'];
$details_txt = $_POST['details_txt'];
$price_txt = $_POST['price_txt'];

-----------------------------------------------------------------------------------------------


however, the PHP is still giving the error message when i test in browser:
HTTP://previewsample.com/loadupdate/update.php

--------------------------------------------------------------------------------
error message is still the same:

almost a step closer to 'updating text in flash' !!!!

what the heck could be wrong with the PHP? i'm going to google that error message .. please let me know if you know what that error is.



<?php
//connect to database
$connect = mysql_connect("db1603.perfora.net", "dbo254844067", "Q77hasTT");
mysql_select_db("db254844067", $connect);
 
//get variables from the flash post
$id = $_POST['id'];
$name_txt = $_POST['name_txt'];
$details_txt = $_POST['details_txt'];
$price_txt = $_POST['price_txt'];
 
 
//get info from database
//select all from the table loadtest where column 'id' equals the variable $'id'
$select = "SELECT * FROM loadtest WHERE `id` = '$id'";
 
//(NOTE The problem here is that php hasn't been told about a variable named $id yet)
 
//This query should reflect the variables you have and the table columns you have
// e.g. $select = "SELECT * FROM loadtest WHERE `name_txt` = '$name_txt";
//This assumes you have a column in your table called name_txt
 
$result = mysql_query($select) or die(mysql_error());
 
//how many rows were found?
//NOTE. Just pointing out this is different to my code above
$numresults = mysql_affected_rows($result);
 
//if no rows were found do this
if($numresults==0) {
 
} else {
 
//else if a row was found, update it
//NOTE again you are using the $id variable here which hasn't been defined.
 
$update = "UPDATE loadtest SET `price_txt`='$price _txt' WHERE `id` = '$id'";
mysql_query($update) or die(mysql_error());
 
?>

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:

Select allOpen in new window

 

by: crooksy88Posted on 2009-09-23 at 08:01:56ID: 25403917

$id = $_POST['id'];

So now you have this line in your PHP file, what is it doing?

 

by: sam928Posted on 2009-09-23 at 08:14:46ID: 25404093

yes that line $id =$_POST['id']; is getting variables from the flash..  correct?
--------------------------------------------
i have fixed the PHP... it was missing a curly bracket at the end..

--------------
but nothing is loading into flash...so obviously then there is nothing to edit... (there is data in mySQL


 

by: crooksy88Posted on 2009-09-23 at 08:32:48ID: 25404366

are you sending id with a value from flash?
e.g. in flash

//add the vars to the sendData object
sendData.id = 2;
sendData.name_xt = "name_txt";
sendData.details_txt = "details_txt"
sendData.price_txt = "price_txt"

--
And in your database table, do you have a column named 'id'?
Is there a record with the id value the same as what you are searching for?
Put your tablename in quotation marks.
$select = "SELECT * FROM `loadtest` WHERE `id` = '$id'";

 

by: sam928Posted on 2009-09-23 at 09:37:26ID: 25405110

yes in my table, the column is named 'id'        and that is the primary , auto increment index.
----------------------------------
i added this line in AS:
sendData.id = 2;                   ...but it did nothing. still blank when i load the .fla
=======================================

Should we have :>>>

loadData.id = 2;
loadData.name_xt = "name_txt";
loadData.details_txt = "details_txt"
loadData.price_txt = "price_txt"


?????\
=======================
since we have both at the beginning of the actionscript: >>>
var sendData:LoadVars = new LoadVars();
var loadData:LoadVars = new LoadVars();

=====================================
also, i added single quotes on the table name but it gave an error message when tested in browser..,, referring to the quotes inserted...so i removed them.



 

by: sam928Posted on 2009-09-23 at 09:39:34ID: 25405132

on the flash side.... what all should i have on the stage?

can you take a look inside the .fla to see if something might be wrong there please?

http://previewsample.com/loadupdate/loadupdate.fla


 

by: crooksy88Posted on 2009-09-23 at 09:47:22ID: 25405222

Give me the details of a database table row and I'll amend your fla so that it works.

ie. I need the table row names and the contents of one of the rows.

 

by: crooksy88Posted on 2009-09-23 at 10:03:26ID: 25405397

Hang on what are you trying to do here?

send data to php so that it updates a database or get data from a database and display it in Flash?

 

by: sam928Posted on 2009-09-23 at 10:47:05ID: 25405849

Currently as I stated from the beginning, all i have is the part where my data loads into flash , and each entry from the database is loaded into its own movie clip.  It is displayed in flash this way..  
-----(here is a working preview of how the data loads)
http://previewsample.com/loaddatacms

===============================
What I am trying to do is edit/update one of the entries that you see.  Obviously there are multiple entries in the data base, so we would need to pick one of those entries and then be able to update it.

For learning purposes, i was just trying to keep it simple and follow what you are trying to do.

But the main objective is to be able to update data.  so if you have a simple way to do it that is different from the way I load the data in, then that will work ;)
==============================================

but i think that once i can see it actually working , and the code that makes it work, i can take it and integrate it with my above file.

hope that makes sense. ?
--------------------------------------------------------

I attached screenshots of the table and the contents..
and here is the username/password/table info if you can get in someway with this?

$connect = mysql_connect("db1603.perfora.net", "dbo254844067", "Q77hasTT");
mysql_select_db("db254844067", $connect);

  • mysql2.JPG
    • 118 KB

    SCREENSHOT OF THE CONTENTS IN THE TABLE

    SCREENSHOT OF THE CONTENTS IN THE TABLE
  • mysql1.JPG
    • 142 KB

    SCREENSHOT OF THE TABLE AND ROWS. ETC

    SCREENSHOT OF THE TABLE AND ROWS. ETC
 

by: crooksy88Posted on 2009-09-23 at 11:25:09ID: 25406253

OK, within your fla file you were attempting to send the variables to php as soon as the swf was run. This meant that it was sending blank data as you didn't have time to fill the text fields in.

So you need a form to fill in, then when you hit the submit button, it send the data to php.

save the attached fla and delete the .txt from the end of the name.

 

by: sam928Posted on 2009-09-23 at 12:13:21ID: 25406760

hi!,

ok i uploaded your .fla.......... and from what i understand so far, i must enter the # of the id.. so for example... if i want to edit the 2nd entry in that table... i must enter '2' in the "input ID number' field you created..and then enter the data that i want to replace the old data with?  correct?

i tried that but it is not updating.. i went into the mySQL database and checked.  was there something else i have to do?


i have the lastest PHP uploaded also.
=============
if it is easier please access my FTP

host: previewsample.com
user; u47663653-22
pass: password

<?php
//connect to database
$connect = mysql_connect("db1603.perfora.net", "dbo254844067", "Q77hasTT");
mysql_select_db("db254844067", $connect);
 
//get variables from the flash post
$id = $_POST['id'];
$name_txt = $_POST['name_txt'];
$details_txt = $_POST['details_txt'];
$price_txt = $_POST['price_txt'];
 
 
//get info from database
//select all from the table loadtest where column 'id' equals the variable $'id'
$select = "SELECT * FROM loadtest WHERE `id` = '$id'";
 
//(NOTE The problem here is that php hasn't been told about a variable named $id yet)
 
//This query should reflect the variables you have and the table columns you have
// e.g. $select = "SELECT * FROM loadtest WHERE `name_txt` = '$name_txt";
//This assumes you have a column in your table called name_txt
 
$result = mysql_query($select) or die(mysql_error());
 
//how many rows were found?
//NOTE. Just pointing out this is different to my code above
$numresults = mysql_affected_rows($result);
 
//if no rows were found do this
if($numresults==0) {
 
} else {
 
//else if a row was found, update it
//NOTE again you are using the $id variable here which hasn't been defined.
 
$update = "UPDATE 'loadtest' SET `price_txt`='$price _txt' WHERE `id` = '$id'";
mysql_query($update) or die(mysql_error());
}
if($result) echo "writing=Ok&";
   else echo "writing=Error";
?>

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:

Select allOpen in new window

 

by: sam928Posted on 2009-09-23 at 12:13:43ID: 25406766

 

by: crooksy88Posted on 2009-09-23 at 12:33:11ID: 25406956

Yes you are correct. Unfortunately I don't have time to sort this out for you.

In the first instance what you need to do is make sure your PHP file is working and is writing to the database. i.e. cut flash out of the equasion.

So you need to create a simple html form that you can fill in and post to your php script. Once you have that working and your database is being written to, we can then look at introducing Flash.

 

by: sam928Posted on 2009-09-23 at 14:18:31ID: 25408059

I have built a form in flash that inserts a new entry into mySQL.. it works fine .. please view and try inserting a new record..

http://previewsample.com/loadupdate
http://previewsample.com/loadupdate/loadupdate.fla
----------------------------------------------------------
I have tried many possibilities and also checked the code 10x.  It is still not updating.

Here is the current PHP below.

we are very close.. i can feel it.. ;))))


<?php
//connect to database
$connect = mysql_connect("db1603.perfora.net", "dbo254844067", "Q77hasTT");
mysql_select_db("db254844067", $connect);
 
//get variables from the flash post
$id = $_POST['id'];
$name_txt = $_POST['name_txt'];
$details_txt = $_POST['details_txt'];
$price_txt = $_POST['price_txt'];
 
 
//get info from database
//select all from the table loadtest where column 'id' equals the variable $'id'
$select = "SELECT * FROM loadtest WHERE `id` = '$id'";
 
//(NOTE The problem here is that php hasn't been told about a variable named $id yet)
 
//This query should reflect the variables you have and the table columns you have
// e.g. $select = "SELECT * FROM loadtest WHERE `name_txt` = '$name_txt";
//This assumes you have a column in your table called name_txt
 
$result = mysql_query($select) or die(mysql_error());
 
//how many rows were found?
//NOTE. Just pointing out this is different to my code above
$numresults = mysql_affected_rows($result);
 
//if no rows were found do this
if($numresults==0) {
 
} else {
 
//else if a row was found, update it
//NOTE again you are using the $id variable here which hasn't been defined.
 
$update = "UPDATE loadtest SET `name_txt`='$name_txt', `details_txt`='$details _txt', `price_txt`='$price _txt' WHERE `id` = '$id'";
//$update = "UPDATE loadtest set name_txt = '$name_txt', details_txt = '$details_txt', price_txt = '$price_txt' where id = '$id'";
 
mysql_query($update) or die(mysql_error());
}
if($result) echo "writing=Ok&";
   else echo "writing=Error";
?>

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:

Select allOpen in new window

 

by: andoneknightPosted on 2009-09-23 at 17:44:06ID: 25409389

Just came back to this - Apologies I didn't see that you mentioned you are using AS2 - I must have ignored that bit ^.^

Unfortunately I can't help, just thought I'd apologise :-)

 

by: sam928Posted on 2009-09-23 at 17:56:11ID: 25409476

@andoneknight..   its something i need to learn ;)))

thank you for your thoughts anyways.

 

by: andoneknightPosted on 2009-09-23 at 17:57:27ID: 25409485

So I just had a quick look anyway ^.^

(I don't know if this is outdated code - downloaded the above loadupdate.fla.txt)

You use:
sendData.id = _root.panel_mc.id.text; ----------> The text field for ID is called id_txt do you mean sendData.id = _root.panel_mc.id_txt.text; ?

I checked your PHP... looks fine.

 

by: sam928Posted on 2009-09-23 at 20:13:42ID: 25409854

@andoneknight... yes thank you for looking... i had fixed that after i reviewed also.. so all instance names for ID are 'id'  .. but that didnt fix the problem yet.. ;))

 

by: crooksy88Posted on 2009-09-23 at 22:45:14ID: 25410348

OK I've uploaded a testing form for you and amended your update.php script.

But I can't access the mySQL admin to see if the database has been updated so you will have to do that and report back. Record 2 should now be set to have the word 'test'.

http://previewsample.com/LoadUpdate/indexform.html

 

by: sam928Posted on 2009-09-24 at 04:40:38ID: 25412185

good morning crooksy88.. i have checked the table and it has not updated.. instead it filled the field with '0'

i attached a picture.
==========================
i dont know if you have seen it or not. but 6 posts before this one please see my comments and the updated file.  I have made a flash form that inserts new records and also you can see the data that is there...

please find the link above (6 posts before this one, and the messages from 'andoneknight')

------------------------------
i have also tried your form and it does not update the data, it just replaces it with a '0' in the 'name_txt' field.



  • mysqldata.JPG
    • 129 KB

    screenshot of data.. not updating .. Notice the '0' in the 'name_txt' fields

    screenshot of data.. not updating .. Notice the '0' in the 'name_txt' fields
 

by: crooksy88Posted on 2009-09-24 at 04:47:49ID: 25412234

I've just used your form to add a record. Has it been inserted?

 

by: sam928Posted on 2009-09-24 at 09:32:30ID: 25415169

yes it has been inserted. you can view all the data by clicking on but 'VIEW DATA' button directly below the form where you inserted the new record.

http://previewsample.com/loadupdate

also here is the source

http://previewsample.com/loadupdate/loadupdate.fla

 

by: crooksy88Posted on 2009-09-24 at 09:50:21ID: 25415330

Your form is working now.

2 issues that I changed.

1. You had two forms both with the same instance name 'panel_mc'
2. Your URL to update.php was incorrect.You had /loadupdate/ when it should have been /LoadUpdate/

The fla is on your FTP server... loadupdate2.fla.

PS. remember to change your database and ftp login settings as you have posted them on this question.
You might want to request this question be deleted.

 

by: sam928Posted on 2009-09-24 at 10:47:00ID: 25415841

which form are you referring to that is working?  because the 'insert new record' form was working already...  but i just tried updating a record again with your 'update' form but it still did not update. ??

also, the .fla you uploaded on the server was no good.. i tried to open it and it said ''unexpected file format''

;((

 

by: crooksy88Posted on 2009-09-24 at 10:52:48ID: 25415899

It is working, you just need to set the form to do something once the response has been received.
I've set it up now to jump to frame 2 so you can see the results.

I've just updated record 16.

I've re-uploaded the fla as CS3

 

by: sam928Posted on 2009-09-24 at 11:09:21ID: 25416075

AWESOMEEEEEEEEEE :))))))

you are the best!

that is wondeful . thank you very much . good fortune will come your way for helping me.
worth a million

and i assume that this works the same way for deleting a record.. i would just need to change the PHP to DELETE instead of UPDATE?


 

by: crooksy88Posted on 2009-09-24 at 11:56:04ID: 25416534

Got there in the end!

Try something like this.
DELETE FROM loadtest WHERE id='$id'

 

by: sam928Posted on 2009-09-24 at 12:51:03ID: 31631272

thanks buddy

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...