Page 1 of 1

PHP to store/retrieve 2 variables

Posted: Tue Apr 12, 2011 8:26 am
by writer
Hi,

I am a beginner using PHP and wondered if it is possible to create a PHP page with a script that can hold the values of 2 variables and then allow these to be retrieved from the page into a SWF?

I am using a third party authoring tool that exports to Flash SWF and can post internet data. Ordinarily, if the data is large, the posting would use a PHP page and PHP script to insert/retrieve data from a database. I've actually set this up for mysql using the software's tutorial.

Problem is that when the SWF is run from a server on a web site, the connection speed to and from the DB is slow and doesn't work (running the SWF on the desktop in a standalone Flash player, and it works perfectly).

Since there are only 2 variables, maybe I can avoid this connection problem by simply placing the 2 variables' values into a PHP page, then retrieving these later, not using any DB.

Is there a way to write a PHP script for a PHP page that can receive 2 variables' values, then when queried, can send these 2 variables' values back to (another separate) SWF? (Each time variables inserted, no need to save old values-overwriting them is OK.)

Any help would be appreciated. Please explain step-by-step, possibly illustrate any way to script this, since I am just beginning to use PHP.

Thank you for your help.

Kind Regards,

writer

Here's the PHP I have used (taken from the software tutorial). It works as mentioned above. Any way to simply hold the 2 variables' values in the PHP page, then access them later?

insert:

Code: Select all

$first = $HTTP_POST_VARS['first'];
$last = $HTTP_POST_VARS['last'];
$address = $HTTP_POST_VARS['address'];
$position = $HTTP_POST_VARS['position'];

$DBhost = "xxxxxx.com";
$DBuser = "mydb";
$DBpass = "xxxxxx";
$DBName = "mydb";

$connect = mysql_connect($DBhost,$DBuser,$DBpass);
$db = mysql_select_db($DBName,$connect);
$query = "INSERT INTO dbname (first, last, address, position) VALUES ('$first','$last','$address','$position')";
$result = mysql_query($query, $connect);
select:

Code: Select all

$DBhost = "xxxxxx.com";
$DBuser = "mydb";
$DBpass = "xxxxxx";
$DBName = "mydb";

$connect = mysql_connect($DBhost,$DBuser,$DBpass);
$db = mysql_select_db($DBName,$connect);
$query = "SELECT * FROM dbname";
$result = mysql_query($query, $connect);

$row = mysql_fetch_array($result );
$data = "&first=".$row['first']."&last=".$row['last']."&address=".$row['address']."&position=".$row['position'];
echo $data