Page 1 of 1

Create average value

Posted: Mon Jan 14, 2008 5:33 pm
by lammspillning
I'm doing a rating function and got a little stucked on the php.
I'm trying to send a value from flash to php, take that value and put it in a database.
I was thinking that I should have three rows in my table: ID, votes_sum and votes_tot. So that I can calculate an average value.

The ID should represent the specific movie or what I'm rating on, votes_sum should be a value that increases depending of the value the php recieves. And the votes_sum should count how many votes have been made on that specific ID.
So far I only figured out something like this, but I dont really know if I'm on the right track..(I'm not so experienced in php:)

Code: Select all

<?php
$DBhost = "localhost";              // Database Server
$DBuser = "user";                    // Database User
$DBpass = "pass";                   // Database Pass
$DBName = "database";               // Database Name
$table = "table";                  // Database Table
 
// Recieve Variables From Flash
         $rate_value =  $_POST['valueToPHP'];
         $name =  $_POST['nameToPHP'];
         
// Insert the data into the mysql table
         $sql = 'INSERT INTO ' . $table . 
                ' (`ID`, 
                   `votes_summa`, 
                   `votes_total`
                  ) 
                  VALUES 
                  (\'' . $name . '\',' 
                   . '\'' . $rate_value . '\'
                   )';
 
?>

Re: Create average value

Posted: Mon Jan 14, 2008 6:58 pm
by jimthunderbird
Yes, I think you are on the right track, but make sure to use mysql_real_escape_string to filter the $_POST variables to prevent sql injection attack.