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 /> ";
}
}
?>