PDA

View Full Version : Loadvars help



- |Flash Man| -
October 10th, 2006, 08:47 PM
Hey,

I have a php file which links to my database and pulls the text required out of there.
is there any problems in my code?? or easier ways? i have used both GET and POST method and still same error
i'm getting the error "onLoad=%5Btype%20Function%5D" in my dynamic text field....any ideas why??

here is my code:

on(release){
questions = new LoadVars;
questions.loadVariablesNum("questions.php", 0, "GET");
questions.onLoad = function(){
_root.questions_txt = questions.questions_txt;
}
}


cheers in advance :)

- |Flash Man| -
October 10th, 2006, 09:30 PM
Hey,

I have a php file which links to my database and pulls the text required out of there.
is there any problems in my code?? or easier ways? i have used both GET and POST method and still same error
i'm getting the error "onLoad=%5Btype%20Function%5D" in my dynamic text field....any ideas why??

here is my code:

on(release){
questions = new LoadVars;
questions.loadVariablesNum("questions.php", 0, "GET");
questions.onLoad = function(){
_root.questions_txt = questions.questions_txt;
}
}


cheers in advance

pbrollwitme
October 10th, 2006, 10:55 PM
first off I would use sendAndLoad rather than the loadVariablesNum function...i find that works best for me. But despite that, did you put the variable name questions_txt in the variable field for the text field or in the instance field? Make sure its in the variable field. basically, this is how i'd lay it out:



on(release){
questions = new loadVars();
questions.sendAndLoad("questions.php", questions, "POST");
questions.onLoad = function(){
var questions_txt = ??
}
}


the ?? is because I don't know how you php is set up so I can't really help you there unless you post your php.

Hope this helps a bit.

ghjr
October 10th, 2006, 11:05 PM
I don't think LoadVars works like that. Try this as see what the trace output is:



var my_lv:LoadVars = new LoadVars();
my_lv.onLoad = function(success:Boolean) {
if (success) {
trace(this.toString());
} else {
trace("Error loading/parsing LoadVars.");
}
};
my_lv.load("questions.php");


Cheers,
ghjr

- |Flash Man| -
October 11th, 2006, 01:06 AM
would this code go on a button or a frame??

- |Flash Man| -
October 11th, 2006, 01:08 AM
also it says that in the output that i can't connect to database its on a localhost the database

- |Flash Man| -
October 11th, 2006, 01:12 AM
i have tried that and where the ?? are i have put $questions as thats how it is in my php?
can u suggest anything else that may be wrong?

lunatic
October 11th, 2006, 01:14 AM
please don't double post. :hair:
I am combining your threads

- |Flash Man| -
October 11th, 2006, 05:55 AM
kk sorry my bad its just i needed a response from both actionscript side and server side and instead of re wording the same prob you get the pic

ghjr
October 11th, 2006, 09:07 AM
Something's wrong with your database connection in your serverside script then. Are you able to connect to it outside of flash?

Cheers,
ghjr

- |Flash Man| -
October 11th, 2006, 07:30 PM
Hey,

yes i can connect to my database through mysql query browser and mysql admin...so it is working i assume but its when i try pass variables through flash when it doesn't work

- |Flash Man| -
October 11th, 2006, 07:39 PM
when i tried ur method with the trace function on this is the error i got:

%3C%3F%0D%0A%24questions%20=%20%24%5FGET%5B%27ques tions%27
%5D%3B%0D%0A%0D%0Amysql%5Fconnect%28%22localhost%2 2%2C%22
root%22%2C%22%22%29%20or%20die%20%28%22couldn%27t% 20connect
%20to%20database%22%29%0D%0Amysql%5Fselect%5Fdb%28 %22quiz%22%29%20
or%20die%20%28%22couldn%27t%20find%20database%22%2 9%3B%0D%0A%0D
%0A%24query%20%3D%20%22SELECT%20quiz%5Fquestions%2 0FROM%20questions
%20WHERE%20questionid%20%3D%201%22%0D%0A%24result% 20%3D%20mysql
%5Fquery%28%24query%29%20or%20die%20%28%22didn%27t %20query%22%29%
3B%0D%0A%0D%0A%3F%3E&onLoad=%5Btype%20Function%5D

i take it means what it says minus the % signs so i take it that there is an error with my php page if you don't mind could u please help me with how u would consider writting the php page with a localhost connection and root username and NULL password??

cheers in advance

JoshuaJonah
October 11th, 2006, 08:33 PM
The problem is in your php, it echoing an error back. Post the PHP, you loadvars is working fine.

- |Flash Man| -
October 11th, 2006, 11:09 PM
okay here is my php code:


<?
$questions = $_POST['questions'];

mysql_pconnect("$host","$user","$pass") or die ("didn't connect to mysql");
mysql_select_db("quiz") or die ("no database");

$query = "SELECT * FROM questions WHERE questionid = 1"
//$result = mysql_query ( $query ) or die ("didn't query");

?>



also how would u set this up if you want to access a localhost server like wamp
where user = root and password = "";

cheers :)

ghjr
October 11th, 2006, 11:37 PM
I take it that you are defining the $host, $user and $pass variables before you call the connect function. If you are not, then there's the first problem.

Run that connect script (only the mysql_connect and mysql_select_db) in a seperate PHP page and see if it works... if ""didn't connect to mysql" shows up then your mysql isn't running or your connection parameters aren't correct.

Cheers,
ghjr

- |Flash Man| -
October 11th, 2006, 11:46 PM
ya i have tried that and its working fine it shows me a white page which i take it means no errors and yes my $host etc are all defined above...its really confusing why?? :S it couldn't be an error with the privillages as i have them all set to my user account??

cheers

ghjr
October 12th, 2006, 12:06 AM
In your post with the PHP script you missed a semicolon:


$query = "SELECT * FROM questions WHERE questionid = 1";

That would make PHP return an error, but not a MySQL error. Try fixing that and running it.

Cheers,
ghjr

- |Flash Man| -
October 12th, 2006, 12:10 AM
tried that and still comes up with that same first error of %20bfunction%5b or whatever it was

hmmm if wouldn't mind would u care making a php script for me for comparison if u dun mind??

cheers

ghjr
October 12th, 2006, 12:33 AM
Try to run this outside of flash, on a php file:




mysql_connect($host, $user, $pwd) or
die("Could not connect: " . mysql_error());
mysql_select_db($db);

$result = mysql_query("SELECT * FROM questions WHERE questionid = '1'");
$row = mysql_fetch_row($result);

echo $result[0];



See if that returns the first column, first record from the questions table (that is if your first id is 1). Don't forget to give values to the host, user, pwd and db variables beforehand.

Cheers,
ghjr