# Newbie Question About Getting Quotes from a Database (PHP/MX2004) - long post

**URL:** https://forum.kirupa.com/t/newbie-question-about-getting-quotes-from-a-database-php-mx2004-long-post/63590
**Category:** programming
**Created:** [September 8, 2004, 7:47am UTC](https://forum.kirupa.com/t/newbie-question-about-getting-quotes-from-a-database-php-mx2004-long-post/63590 "2004-09-08T07:47:05Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Northchild](https://avatars.discourse-cdn.com/v4/letter/n/ecccb3/32.png) [@Northchild](https://forum.kirupa.com/u/Northchild)
#### Post date: [September 8, 2004, 7:47am UTC](https://forum.kirupa.com/t/newbie-question-about-getting-quotes-from-a-database-php-mx2004-long-post/63590/1 "2004-09-08T07:47:05Z")

</div>

Hi all,

This is my first time integrating PHP with Flash, and I’m a bit unsure of myself. I’m using MX2004 and have PHP with MySQL support on a remote server. Overall, I’m trying to get a simple “random quote of the day” thing working.

In the MySQL database, I have a table called quotes. This table has a field called allQuotes. allQuotes has 12 records with random semi-funny stuff that I’ve found on the web.

I have a FLA file with a movie clip with the instance name mcQuote. The movie clip contains one dynamic text field named txtQuote.

On a frame on the main timeline I have the following code:

```auto

_root.mcQuote.onLoad = function()
 
{
loadVariables("[https://www.drunkentrolls.com/read.php?file=quotes.php](https://www.drunkentrolls.com/read.php?file=quotes.php)", "_root.mcQuote", "POST");
}

```

On the server, the file quotes.php contains this code:

```auto

 
<?php
 
print "_root.mcQuote.txtQuote=$myQuote";
 
?>

```

On the server, the file read.php contains this code:

```auto

<?php
 
if($file)
 
{
$link = mysql_connect(edited, edited, edited)
	 or die("Failed to connect to database.");
 
$query = "SELECT content FROM files WHERE filename='$quote.php'";
$result = mysql_query($query) 
	 or die("Failed to execute query.");
 
mysql_close($link);
 
$myQuote = mysql_fetch_array($result, MYSQL_ASSOC);
 
mysql_free_result($result);
 
print "txtQuote=$myQuote";
}
?>

```

Now, if I upload all of this to the server, it’s not going to work because I’m an artist and these programming things never, ever work for me when I first try them. Also, I don’t anticipate getting the php to pick out a random quote and sending it to the flash player anytime this week. I would settle for getting ANY ONE field from this table printed out in the dynamic text file. Any hand-holding would be sooooo appreciated at this point.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [September 8, 2004, 8:02am UTC](https://forum.kirupa.com/t/newbie-question-about-getting-quotes-from-a-database-php-mx2004-long-post/63590/2 "2004-09-08T08:02:59Z")

</div>

this has been by far the most illogical thing i have ever seen.

Congrats !!!

just call a page “quotes.php” from loadVariables

in it :  
$link = mysql\_connect(edited, edited, edited) or die(“Failed to connect to database.”);

$query = “SELECT myfield FROM allquotes ORDER BY RAND()”;  
$result = mysql\_query($query) or die(“Failed to execute query.”);  
$myQuote = mysql\_fetch\_array($result, MYSQL\_ASSOC);  
print “txtQuote=” . $myQuote[myfield];

in flash you will get a variable  
\_root.txtQuote with the random quote

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [September 8, 2004, 8:52am UTC](https://forum.kirupa.com/t/newbie-question-about-getting-quotes-from-a-database-php-mx2004-long-post/63590/3 "2004-09-08T08:52:48Z")

</div>

Woo hoo! I’ll have to collect a prize for the sheer illogic of it all. 😉

All right, I’ve simplified it (quite) a bit as per your advice. Database has a table called allQuotes with one field named quotes.

Flash file has a dyamic text field named txtQuote on the main timeline, plus this code:

```auto

loadVariables("quotes.php", POST);

```

quotes.php has this code:

```auto

<?php
$link = mysql_connect(dbname, username, password) or die("Failed to connect to database.");
$query = "SELECT quotes FROM allQuotes ORDER BY RAND()";
$result = mysql_query($query) or die("Failed to execute query.");
$myQuote = mysql_fetch_array($result, MYSQL_ASSOC);
print "txtQuote=" . $myQuote[quotes];
?>

```

This still isn’t working, but at least I understand this code a bit better than the tutorial that I was working from originally. 🙂 Anything else that I can try?

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [September 9, 2004, 12:13am UTC](https://forum.kirupa.com/t/newbie-question-about-getting-quotes-from-a-database-php-mx2004-long-post/63590/4 "2004-09-09T00:13:25Z")

</div>

bump?

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [September 9, 2004, 4:11am UTC](https://forum.kirupa.com/t/newbie-question-about-getting-quotes-from-a-database-php-mx2004-long-post/63590/5 "2004-09-09T04:11:13Z")

</div>

check the file locations.

you have used  
loadVariables(“quotes.php”, POST);

so it must be referenced via a web url  
like http:\…\myflash.swf

or use loadVariables(“http:\…\quotes.php”, POST);

also check the syntax of loadVariables

the PHP code seems to be fine but urlencode the $myQuote[quotes]; before print

also run the quotes.php from a browser to check the output.

then call it from flash

cheers
