Flash Database Step By Step Tutorial - Part 3: When use vote a choice, flash application will send it to server. Then server will update data (update polling.txt).
This is saving function. Add to polling.php:
function saveData(){
global $file_data;
if(number_format($_GET['num']) < 1) die("registered=false");
// open file
$fp_array = file($file_data);
$fp = fopen($file_data,"r+");
$temp_string = "";
// read file
foreach($fp_array as $key => $value){
// extract each lines
$line = explode('=', $value);
$name = $line[0];
$val = eregi_replace("\r\n","",$line[1]);
// if as votes
if(substr($name,0,5)=='votes'){
$val = (int)eregi_replace("\r\n","",$line[1]);
$match= (int)(substr($name,5,2));
// if the index same as choice, add 1
if($match == $_GET['num']){
$val++;
}
}
// write this line
$temp_string .= $name."=".$val."\r\n";
}
fwrite($fp, $temp_string);
fclose($fp);
}