Okay this is what I have....
<?php
if (!isset($mode))
{
$mode = 'index';
}
switch($mode) {
case 'rate':
?><p align="center"><b>Rate Item</b></p><?php
// Database Connection Variables, adjust it for your server
// MySQL Connection Variables
$user="user";
$pass="pw";
$hostname="localhost";
$dbase='db';
$connection = mysql_connect("$hostname" , "$user" , "$pass");
$db = mysql_select_db($dbase , $connection);
$query = "SELECT * from names where nameid='$nameid' ";
$result = mysql_query($query);
while ($row=mysql_fetch_array($result))
{
$rateid = $row["rateid"];
$nameid = $row["nameid"];
$totalcount = $row["totalcount"];
$totalsum = $row["totalsum"];
// compute new total ratings
$totalsum = $totalsum + $rateitem;
// Increment total count by 1 since 1 more user rate item
$totalcount = ++$totalcount;
// Compute new average, take note of division by zero error
$newavg = $totalsum / $totalcount;
// round new average to 2 dec place.
$newavg = round($newavg,2);
// Now update rating table with new values.
$newquery = "UPDATE rate set avgrate = '$newavg', totalsum='$totalsum', totalcount='$totalcount'
where nameid='$nameid' ";
$newresult = mysql_query($newquery);
if ($newresult)
{
echo "Thank you, Item has been rated.";
}
}
mysql_free_result($result);
break;
case 'index':
?><p align="center"><b>Rate Item</b></p>
<form action="<?php echo "rate.php?mode=rate&itemid=$itemid"; ?>" method="post">
<SELECT name="rateitem" >
<option value="10">10</option>
<option value="9">9</option>
<option value="8">8</option>
<option value="7">7</option>
<option value="6">6</option>
<option value="5">5</option>
<option value="4">4</option>
<option value="3">3</option>
<option value="2">2</option>
<option value="1">1</option>
</select><input type="submit" value="Rate"></form>
<?php
break;
}
?>
However I REALLY don't think that it's doing it right... I have two tables names and rate. The nameid is on the names table and the rest is on the rate table.
I am really confusing myself...
Okay so this is what I need to know. First, I already have an established database with some names in it. I want to be able to rate those.
Here is my database info if you wanna see what I am talking about:
http://www.simply-baby.net/forum/vbaindex.php?page=babynames
And here is where they enter the names. Ignore the rating thing that is there because obviously it doesn't work! lol
http://www.simply-baby.net/forum/vbaindex.php?page=entername