In addition to building animation clips on the fly, Flash canalso be used to build simple Web forms to collect user data on your Website. This article demonstrates the process, showing you how to buildsimple Flash forms and link them to server-side scripts for furtherprocessing.
Obviously, that was a very primitive example, though one that did demonstrate the concept of integrating user-supplied data with a server-side script via a Flash movie. Now, how about a twist?
This next example uses the data entered into a Flash form to query a database and return a list of matches. In order to create the form, create a new Button symbol, in much the same way as you created the one on the previous page. Name the form variable within the symbol "q", and add a copy of the instance to the Flash movie.
Once that's done, add some ActionScript to the symbol instance, referencing the server-side script "search.php" - this time, use POST to send the form variables to the script.
on (keyPress "<Enter>") {
getURL ("search.php", "", "POST");
}
All that's left now is to write the PHP script "search.php".
Here's what mine looks like:
<html>
<head><basefont face="Arial"></head>
<body>
<h2>Search Results</h2>
<ol>
<?
// search.php
// get query term
$query = trim($_POST['q']);
// open connection to database
$connection = mysql_connect("localhost", "user", "pass") or die ("Unable
to connect!");
mysql_select_db("db20139a") or die ("Unable to select database!");
// formulate and execute query
$query = "SELECT * FROM data WHERE tag LIKE '%$query%' OR keyword LIKE
'%$query%'"; $result = mysql_query($query) or die("Error in query: " .
mysql_error());
// get record
while($row = mysql_fetch_object($result))
{
echo "<li>";
echo "<a href=go.php?id=$row->id>$row->tag</a>";
echo "<br>$row->title";
echo "<p>";
}
// clean up
mysql_close($connection);
?>
</ol>
</body>
</html>