PDA

Click to See Complete Forum and Search --> : [RESOLVED] Flash site on server not comminicating with database


Nightwalker83
Dec 12th, 2009, 09:22 PM
Hi,

I'm not sure where this belongs! However, my problem is that a flash website that I created earlier this year doesn't won't to communicate with the database on the webhost. I know the connection to the webhost is working because I am using the exact same connection code as the html version of the website which works.


<?php
//connect to db
$conn = mysql_connect("mysql11.**********.com", "user", "password");
if (!$conn) {
die("Connection failed: " .mysql_error());
}
// Database connection variables
$dbDatabase = "a2834022_bazaarc";
?>


However, when I attempt to send the information to the database I get:


Transfering data from error.**********.com


whereas the html website retrieves and sends information to the database as expected. The strange thing is that the flash website works when it is on my local machine using "localhost".

I have tried replacing:


var dataurl:String = "http://localhost/Bazaar Ceramics/";


with


var dataurl:String = "http://astafeweb.net16.net/Bazaar Ceramics/";


with the server name as it appears in the browser's address bar but it doesn't work. The only other thing I can think of is that I can't have two websites connecting to the same database or that connections are getting mixed up somehow.

Edit:

I have even tried changing the dataurl:


var url:String = "http://mysql11.**********.com/Bazaar Ceramics/";


Although, while I no longer receive the above error the script seems to stop working after about 30 seconds and still doesn't send/receive information to the database.

Thanks,


Nightwalker

kows
Dec 13th, 2009, 12:08 AM
if you are actually connecting to the files in this (http://astafeweb.net16.net/Bazaar%20Ceramics/flash/dynamicWebsite/) directory, then none of them are even connecting to your database (they're trying to connect to localhost with user admin and using no password). if not, then the URL your code is looking at is just going to an empty directory listening anyway. so I'm not even sure what you're trying to do.

either way, this is simply a problem with whatever PHP files you're loading, because your Flash file should have no problem just doing a simple URL request. but, you're not giving us enough information about them to really help.

Nightwalker83
Dec 13th, 2009, 03:37 AM
Well, it should work if I just replaced "localhost" with the name of the hosting server because as far as I'm aware nothing else would have changed.

Edit:

I have changed the user name and password in the connection files to those I am using on the server but the result still remains the same.

kows
Dec 13th, 2009, 11:29 AM
all you need to do is ensure that the PHP files you're connecting to within your flash file are working properly. load them in your browser and ensure there are no errors. then, run your flash file using the same URL.

SambaNeko
Dec 13th, 2009, 01:57 PM
Flash also has cross-domain security restrictions (http://kb2.adobe.com/cps/142/tn_14213.html). Where is your SWF hosted? Where is your database hosted?

Nightwalker83
Dec 13th, 2009, 07:27 PM
all you need to do is ensure that the PHP files you're connecting to within your flash file are working properly. load them in your browser and ensure there are no errors. then, run your flash file using the same URL.

I think the problem is I can't figure out which link I need to put in the flash file whether its the Server Name mentioned in the account information, the domain name or mysql host address. With the html website I just had to put the mysql host address in the php files.

Flash also has cross-domain security restrictions (http://kb2.adobe.com/cps/142/tn_14213.html). Where is your SWF hosted? Where is your database hosted?

They are all host on **********.com.

kows
Dec 13th, 2009, 08:39 PM
.. I don't know how you wouldn't know which file to use.

you don't put in your server name, or your domain name, or your MySQL server name.

say you have a website. it's located at http://whatever.com/html/. say you have a flash version of this same website that uses php as a backend. the php files that flash uses are located at http://whatever.com/flash/. so, you put your URL to the php files that output flash crap instead of using the URL that you would normally browse to in a web browser.

Nightwalker83
Dec 13th, 2009, 09:00 PM
.. I don't know how you wouldn't know which file to use.


Maybe because I have never connected a flash website to a database on a website before nor have I seen an example of flash using the connect as if the file as on the server.


say you have a website. it's located at http://whatever.com/html/. say you have a flash version of this same website that uses php as a backend. the php files that flash uses are located at http://whatever.com/flash/. so, you put your URL to the php files that output flash crap instead of using the URL that you would normally browse to in a web browser.

This is what I put to get the flash site to work on local host:


var url:String = "http://localhost/Bazaar Ceramics/flash/dynamicWebsite/adminLogin.php";


and seeing as it was now on a server replacing localhost with url of the site leaving the other parts as is. This is what I said in my original post.

kows
Dec 13th, 2009, 09:29 PM
if you want to get technical, you actually have done it before because connecting to a "website" on your local machine (localhost) is just like connecting to a live website :/ but, whatever.

you posted this before:
var dataurl:String = "http://astafeweb.net16.net/Bazaar Ceramics/";
which is no where near the same URL as what you just posted. and, just like I said before, the URL above is just a directory listing... if you put that URL in, then it's not going to do anything.

Nightwalker83
Dec 13th, 2009, 09:43 PM
if you want to get technical, you actually have done it before because connecting to a "website" on your local machine (localhost) is just like connecting to a live website :/ but, whatever.

you posted this before:
var dataurl:String = "http://astafeweb.net16.net/Bazaar Ceramics/";
which is no where near the same URL as what you just posted. and, just like I said before, the URL above is just a directory listing... if you put that URL in, then it's not going to do anything.

I have used:


var url:String = "http://astafeweb.net16.net/Bazaar Ceramics2/flash/dynamicWebsite/customerUpdate.php";


However, it is still not working.

kows
Dec 13th, 2009, 10:32 PM
okay.. except the script you're pointing to still doesn't work. I don't know what you don't understand about this -- just because you're making this PHP script for your flash interface doesn't mean a web browser can't still interact with it. I just went to your URL (http://astafeweb.net16.net/Bazaar Ceramics2/flash/dynamicWebsite/customerUpdate.php), and it's not connecting to your database, which is the exact problem I mentioned to you before.

PHP is PHP. PHP has absolutely nothing to do with your flash stuff -- in fact, they are completely and absolutely separate. your flash stuff simply relies on your PHP stuff to work. now, you just need to make sure the PHP scripts you're using actually work.

Nightwalker83
Dec 13th, 2009, 11:09 PM
This is getting annoying! I keep overwriting the connections files, anyway, now I put the connect like I do in my first post with the correct username and password for the database and string in my previous post However, I am receiving error in the first post again.

I think I will jut post one of the flash files I'm using on here and see if someone can look at it and figure out the problem for me.

Edit:

I have attached one of the flash files!

Removed file!

kows
Dec 14th, 2009, 12:18 AM
ugh. excuse the frustration -- but do people in the computing world still not know about relative and absolute paths?! this should seriously be a schooling requirement of some kind!

if you are going to the path: xml/WHATEVER.xml, then your flash file must be in a directory that has the sub-directory xml in it with the file WHATEVER.xml in that sub-directory. I opened your flash file and changed the first line of actionscript to:
var req: URLRequest = new URLRequest("http://astafeweb.net16.net/Bazaar%20Ceramics2/xml/menuDef.xml"); //Remove the "/" before the folder name for the splash page.
and it worked fine. imagine that. it loaded your menu text or whatever. I assume that's what it does, anyway.

it still has some errors, but they seem more related to the way you made this than anything.

Nightwalker83
Dec 14th, 2009, 01:04 AM
ugh. excuse the frustration -- but do people in the computing world still not know about relative and absolute paths?! this should seriously be a schooling requirement of some kind!


What? The link that is in the file works on localhost! Why should it be any different when the website is on a server?

Anyway, what about lines 5 and 31?


var i:int
var myXML:XML = new XML()
var link: URLRequest = new URLRequest("xml/menuDef.xml"); //Remove the "/" before the folder name for the splash page.
var xmlloader:URLLoader = new URLLoader(link);
var dataurl:String = "http://astafeweb.net16.net/flash/dynamicWebsite/getData.php";
xmlloader.load(link);
xmlloader.addEventListener(Event.COMPLETE,dataLoaded);
var prodreq: URLRequest = new URLRequest(dataurl);
var loader:URLLoader = new URLLoader();
prodreq.method = URLRequestMethod.POST;
//Button code
this["btnSubmit"].buttonMode = true;
this["btnSubmit"].mouseChildren = false;
function dataLoaded (event: Event){
myXML = new XML(xmlloader.data);
for (i = 0; i < 6; i++){
var j:int = i+ 1;
/**3 is the line in the
xml the labels start from. (i) starts counting from the 4th line until the end
specified above.**/
}
this["btnSubmit"].btText.text = myXML.child(4).child(3);
}
//Create the loader object
stop();
//holds the login details from the database
var dataloader:URLLoader = new URLLoader();
//Create a URLVariables object to store the user details
var variables:URLVariables = new URLVariables();
//Create the URLRequest object to specify the file to be loaded and the method ie post
var url:String = "http://astafeweb.net16.net/flash/dynamicWebsite/custLogin.php";
var req: URLRequest = new URLRequest(url);
req.method = URLRequestMethod.POST;
//Send the customer login information to the database for validation purposes
req.data = variables;
//Retrieves the customer data and populates the customer details form
prodreq.data = variables;

function submitHandler(event:MouseEvent):void {
//Check username and password fields are not empty
if (tiUsername.text !=null && tiPassword.text !=null
&& tiUsername.text != "" && tiUsername.text != ""){
//Populate variables with values for username and password
variables.username = tiUsername.text;
variables.uPassword = tiPassword.text;
//Send data to php script
dataloader.load (req);
}else{
tbResult.text = "You must enter a login and password.";
}

}
btnSubmit.addEventListener(MouseEvent.CLICK, submitHandler);
dataloader.addEventListener(Event.COMPLETE, contentLoaded);
function contentLoaded (event:Event):void {
var v:URLVariables = new URLVariables(event.target.data);
tbResult.text = v.authenticated;
if (v.authenticated == "true") {
gotoAndStop ("customerDetails");
}else{
tbResult.text = "Login does not exist on server.";
}
}

kows
Dec 14th, 2009, 01:50 AM
practically none of the code you posted there was even in the flash file you uploaded, just for reference.

anyway, the URL you are looking for in your flash file, AGAIN, does not exist. this URL (http://astafeweb.net16.net/flash/dynamicWebsite/getData.php), from your flash file, does not exist. it can't open something that doesn't exist. you're missing the whole "Bazaar Ceramics" directory in your URLs :/

this is beginning to feel like a waste of my time :X if you absolutely need to, open your PHP files in your browser, when they work, copy and paste the URL into your flash file.

and, excuse me on the XML file thing -- apparently flash will run from the directory the object is loaded into, not the directory the flash object resides itself. but, I'm not a flash guy to say the least.

Nightwalker83
Dec 14th, 2009, 05:09 AM
practically none of the code you posted there was even in the flash file you uploaded, just for reference.


Yes, it was! The code was in the library.


anyway, the URL you are looking for in your flash file, AGAIN, does not exist. this URL (http://astafeweb.net16.net/flash/dynamicWebsite/getData.php), from your flash file, does not exist. it can't open something that doesn't exist. you're missing the whole "Bazaar Ceramics" directory in your URLs :/


Nothing is working! I know my code is correct because it works on localhost and the html version is working on the server. I reckon it is the server causing the problem because it loads two of the same files when I only click on the open button in the server file manager once to open the file.

I reckon I will send the host an email asking whether it's possible to use flash with their server and if so how because I have tried every url combination I can think of and the site is still not communicating with the database.

kows
Dec 14th, 2009, 08:23 AM
like I stated before, I'm not a flash guy. if the actionscript wasn't on the timeline, I didn't see it.

anyway, I don't seem to have the means to help you with this. try a different host and see if it works.

SambaNeko
Dec 14th, 2009, 11:14 AM
Yes, it was! The code was in the library.

When you offer your code for others to look at, it's a good idea to describe what the code does - "first it loads some data from XML, then when you click one of the buttons it makes a new instance of either customerLogin or regPage." It's not fair to kows (or anyone) to expect him to go find your code. (Also there's no "regPage" object in your library - should it be registrationPage?)

In any case, I don't get what the mystery is at this point: the URLs in your Actionscript don't appear to exist. It doesn't matter if your code's correct when the code's not there.

Nightwalker83
Dec 14th, 2009, 09:28 PM
like I stated before, I'm not a flash guy. if the actionscript wasn't on the timeline, I didn't see it.

anyway, I don't seem to have the means to help you with this. try a different host and see if it works.

I sent an email to them saying the following:


Hi,

What is the address I need to put in my files files for the server location? I tried any number of different combination domain name, sql addess, etc but nothing I have tried works.

The configuration of the code is:

var dburl:String = "http://localhost/Bazaar%20Ceramics2/flash/dynamicWebsite/createBazaarCeramics.php";

That is what I used to test on localhost but I am confused about what I need to put when I upload the files to **********.com?

Thanks,


Their response:


Hello,

Our team would be more than happy to help you with any problem you encounter. However, we will only provide free support for our system and services. We will help you with basic problems associated with getting scripts running, but if you need help with third-party software, contact the authors of that software or query Google.com with error message you get.

It is not possible for us to provide help for everyone, fix PHP errors or develop your website as it would require a lot of administrative time. We focus in getting our servers and services up and running.

However, you can upgrade your account and we will provide you with full help in installing your scripts, developing your website and fixing errors.

Best Wishes,
Volunteer Staff


Well, I have figured out that it isn't a php problem so I guess I will just have to hope someone on the adobe forums has a solution using action script 3.

When you offer your code for others to look at, it's a good idea to describe what the code does - "first it loads some data from XML, then when you click one of the buttons it makes a new instance of either customerLogin or regPage." It's not fair to kows (or anyone) to expect him to go find your code. (Also there's no "regPage" object in your library - should it be registrationPage?)


Ah ok! My mistake yeah, the code is in there but if just refers to the object using a different name but its still the same object.

Edit:

Well, after some thinking I decided to try and see if just putting the name of the file instead of the url, so:


var url:String = "customerUpdate.php";


instead of


var url:String = "http://astafeweb.net16.net/Bazaar Ceramics2/flash/dynamicWebsite/customerUpdate.php";


and what do you know? For the data storage pages it worked. However, for some reason the others failed even though it was using the same method but that is a start.

Also, moving the flash "*.swf" files into the directory where they php files they were to were located helped.

Nightwalker83
Dec 17th, 2009, 08:35 PM
I have managed to get the website to run correctly on localhost using the above configuration. That is moving the "*.swf" files and the html in to the same directory as the php files and writing the files strings like posted above as well as adding "../../" to the xml,css and javascript paths to get those files working correctly. I reckon it might just be the server I am using that is causing problems getting the website to work correct. I will see if I can get it working on a different server.

Edit:

It is their server causing the trouble because now my html website is malfunctioning on their server and I have not touch the code. Worse still on their website they claim:


Uptime 99% 99.9%

Nightwalker83
Dec 21st, 2009, 09:31 PM
Moving the website to a paid host worked without any problems using my original scripts! To my surprise the server uses "localhost" to connect the the database rather than having to put the name or url on the site in the php.

Using:


<?php
//connect to db
$conn = mysql_connect("localhost", "user", "password");
if (!$conn) {
die("Connection failed: " .mysql_error());
}
// Database connection variables
$dbDatabase = "a2834022_bazaarc";
?>


I was able to connect the the database without any problems.

kows
Dec 21st, 2009, 10:36 PM
uhh, yeah, that really wouldn't have changed anything.. as long as your PHP scripts worked properly (in a browser), the database server address really wouldn't have made any sort of impact. sounds like you just never fixed your PHP scripts so that they actually worked :/

but, whatever.

Nightwalker83
Dec 22nd, 2009, 03:06 AM
uhh, yeah, that really wouldn't have changed anything.. as long as your PHP scripts worked properly (in a browser), the database server address really wouldn't have made any sort of impact. sounds like you just never fixed your PHP scripts so that they actually worked :/

but, whatever.

Yeah, the scripts worked correctly in the first place! I double checked the code of the website before I uploaded it to the new host. The code was almost identical I change the connection variables for the database. However, I suspect it was the host I was using causing the problems. I just checked that server by re-uploading my site to it and I was informed that the site had been attacked.

Edit:

I downloaded the exact same site from the new host and tried it on the host I was using just changing the connection variables along the way and recreating the database. However, the problem retrieving the information from the database still occurs when using the website on the server. I don't see why it is though because the paths to the connection files are exactly the same as those in the output flash pages.

Edit II:

I have attached the customers page code so you can look at it and see what if anything I am doing wrong.

Here is the exported database code:


-- MySQL dump 10.11
--
-- Host: localhost Database: a2834022_bazaarc
-- ------------------------------------------------------
-- Server version 5.0.81-community

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

--
-- Table structure for table `customers`
--

DROP TABLE IF EXISTS `customers`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `customers` (
`cid` int(2) NOT NULL auto_increment,
`FName` varchar(30) collate latin1_general_ci default NULL,
`LName` varchar(30) collate latin1_general_ci default NULL,
`Email` varchar(50) collate latin1_general_ci default NULL,
`Streetname` varchar(20) collate latin1_general_ci default NULL,
`Housenum` char(3) collate latin1_general_ci default NULL,
`Suburb` varchar(20) collate latin1_general_ci default NULL,
`Postcode` varchar(6) collate latin1_general_ci default NULL,
`Country` varchar(20) collate latin1_general_ci default NULL,
`Phone` varchar(10) collate latin1_general_ci default NULL,
`Username` varchar(10) collate latin1_general_ci default NULL,
`Password` varchar(8) collate latin1_general_ci default NULL,
PRIMARY KEY (`cid`)
) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `customers`
--

LOCK TABLES `customers` WRITE;
/*!40000 ALTER TABLE `customers` DISABLE KEYS */;
INSERT INTO `customers` VALUES (2,'q','q','q','q','q','q','q','q','q','q','q'),(3,'a','a','a','a','a','a','a','a','a','a','a');
/*!40000 ALTER TABLE `customers` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

-- Dump completed on 2009-12-22 11:00:01

kows
Dec 22nd, 2009, 11:11 AM
well, I have absolutely no idea what I'm looking for in your code, but one thing I did find was this:
$update = "update customers set FName='$fname'; LName='$lname'; where customerid='$cid'";

semi-colons in MySQL, like in PHP, are terminators. this lets both MySQL and PHP know that this is the "end" of a command. you're ending your SQL query early. if that query executes, every first name would be set to $fname, and PHP doesn't let you run multiple queries with one call to mysql_query(). however, the rest of the queries would produce errors, and I don't know if MySQL would outright ignore them because PHP might only send the first query, or if MySQL will see your entire query and just fail altogether or at least send back a failure message after successfully querying the first query (thinking about it now, that would be an interesting thing to test). now, hopefully you can make sense of that.

either way, the whole issue before was you weren't even connecting to the database server before and you never fixed it (or you apparently never understood what I was talking about when I kept linking you to your own files on your server that were not connecting to your database). if all of your scripts work fine on your personal webserver, then it stands to reason that you might just be doing something wrong on a live server. post links to every single full URL that your Flash file interacts with so that I, or you, can make sure they are actually connecting to the database this time.

penagate
Dec 22nd, 2009, 05:03 PM
To my surprise the server uses "localhost" to connect the the database rather than having to put the name or url on the site in the php.

It's little wonder your code never worked if you are confusing URLs with host names.

Nightwalker83
Dec 22nd, 2009, 07:16 PM
It's little wonder your code never worked if you are confusing URLs with host names.

Well, on some articles I've read online the author has used the url of the website in their example and others say to use a different link.

well, I have absolutely no idea what I'm looking for in your code, but one thing I did find was this:
$update = "update customers set FName='$fname'; LName='$lname'; where customerid='$cid'";

semi-colons in MySQL, like in PHP, are terminators. this lets both MySQL and PHP know that this is the "end" of a command. you're ending your SQL query early. if that query executes, every first name would be set to $fname, and PHP doesn't let you run multiple queries with one call to mysql_query(). however, the rest of the queries would produce errors, and I don't know if MySQL would outright ignore them because PHP might only send the first query, or if MySQL will see your entire query and just fail altogether or at least send back a failure message after successfully querying the first query (thinking about it now, that would be an interesting thing to test). now, hopefully you can make sense of that.


Yeah, that was a slight over-sight I think I meant to a comma instead of a semi-colon.

Edit:

I tested the above code on the new server and it is working as it is suppose to, importing and exporting the data to the database so I don't know what is happening on the other host I was using.