# Actionscript 3 and MySQL

**URL:** <https://forum.kirupa.com/t/actionscript-3-and-mysql/272036>\
**Category:** flash\
**Created:** [October 1, 2008, 2:44pm UTC](https://forum.kirupa.com/t/actionscript-3-and-mysql/272036 "2008-10-01T14:44:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![romeoa](https://avatars.discourse-cdn.com/v4/letter/r/e8c25b/32.png) [@romeoa](https://forum.kirupa.com/u/romeoa)\
**Post date:** [October 1, 2008, 2:44pm UTC](https://forum.kirupa.com/t/actionscript-3-and-mysql/272036/1 "2008-10-01T14:44:40Z")

</div>

Hi,

I am trying to get Flash to insert info into a table in a MySQL DB. So far I am not having any luck. I am using PHP as the in between.  
Any help would be great.

Thanks in advance,

Here is my actionscript 3 code.

stop();

```
    submit.addEventListener(MouseEvent.CLICK, sendData)
    function sendData(evt:MouseEvent){
        if(totwHeadline.text!="" && totwContent.text !=""){
            var myData:URLRequest = new URLRequest("insert.php")
            myData.method = URLRequestMethod.POST
            var variables:URLVariables = new URLVariables()
            variables.Headline = totwHeadline.text
            variables.Content = totwContent.text
            myData.data = variables
            var loader:URLLoader = new URLLoader()
            loader.dataFormat = URLLoaderDataFormat.VARIABLES
            loader.addEventListener(Event.COMPLETE, dataOnLoad)
            loader.load(myData)

```

} else status\_txt.text = “All fields are mandatory”;  
}  
function dataOnLoad(evt:Event){  
if(evt.target.data.writing==“Ok”) {  
gotoAndStop(2);  
} else status\_txt.text = “Error in saving submitted data”;  
}

Here is my php code.

\<?php  
//Capture data from $\_POST array  
$headlineCopy = $\_POST[‘Headline’];  
$contentCopy = $\_POST[‘Content’];  
//Connection to database  
$connect = mysql\_connect(“localhost”, “username”, “password”);  
mysql\_select\_db (“totw”, $connect);  
//Perform the query  
$result = mysql\_query(“INSERT INTO thoughtentry(headline, content) VALUES(’$headlineCopy’, ‘$contentCopy’”);  
if($result) echo “writing=Ok&”;  
else echo “writing=Error”;

```
$query = 'SELECT * FROM thoughtentry';

```

if($r = mysql\_query($query))  
{  
while ($row = mysql\_fetch\_array ($r))  
{  
print "{$row[‘headline’]} \<br /\> {$row[‘content’]}\<br /\> \<br /\> ";  
}

}  
?\>
