• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2185
  • Last Modified:

Simple PHP, MySQL and ActionScript 3.0 Integration

Dear Master Experts,

I have problem to integrate AS3, PHP and MySQL the code doesn't work
please check my code bellow , i really need your advice and suggestion.
I made this code it's very simple what i want is i just want to insert data to MySQL database

Thanks and regards.
Ervan.
// --------------- AS Script File ---------- //
var myname:String = "Panda";
 
function sendData():Boolean
	{
  	var request:URLRequest = new   URLRequest("http://localhost/test/urlvariable/add.php");
	var variables:URLVariables = new URLVariables();
	variables.giveName = myname;
	request.data = variables;
	request.method = URLRequestMethod.POST;
			
	var loader:URLLoader = new URLLoader();
	loader.dataFormat = URLLoaderDataFormat.VARIABLES;
	loader.load(request);
	return true;
	}
 
 
on(click){
function doStopSymbol(event:MouseEvent)
       {
	sendData();
       }
}
 
//------------------ add.php (file) ------------------- //
 
<?php
	$posted = $_POST['giveName'];
	
	// Connection DB
		$link = mysql_connect(locahost, root, password, dbname );
 
		if (!$link) {
			die('Connection Impossible: ' . mysql_error());
		}
		else{
			$sql = "INSERT INTO contactname (id, name) VALUES ('', '$posted')";
			mysql_query($sql);
			echo "answer=$posted";
		}
	
		// Disconnect DB
	mysql_close($link);
//	}
?>
 
 
//------------------ SQL ------------------- //
CREATE TABLE contactname(
  ID int(5) NOT NULL auto_increment,
  name text NOT NULL,
  PRIMARY KEY  (ID)
)

Open in new window

0
beyoursound
Asked:
beyoursound
  • 2
1 Solution
 
aldanchCommented:

32: $link = mysql_connect(locahost, root, password, dbname );
 
Shouldn't this be...
 
$link = mysql_connect(locahost, root, password);
mysql_select_db(dbname);
 
The 4th parameter is a BOOL that determines if it a new link or not.

Open in new window

0
 
aldanchCommented:
Just curious as to why you gave me a B. If I can understand why, it will help me in the future when dealing with other questions.

I am glad my solution solved your problem nonetheless.

Thanks.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now