-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrating.php
25 lines (21 loc) · 979 Bytes
/
rating.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<?php
session_start();
if (isset($_GET['id'])) {
include('connection.php');
$id=$_GET['id'];
$sql="SELECT Rating, TimesRated FROM productmaster WHERE ProductID=$id";
$query=mysql_query($sql);
$row=mysql_fetch_row($query);
$rating=$row[0]; //rating stored in database
$count=$row[1]; //total number of ratings stored in datase
$user_rating=$_GET['val']; //receiving the rating input from the user
$new_count=$count+1; //this is the new count for the total numer of ratings
$avg=(($count*$rating)+$user_rating)/$new_count; //this is the new total i.e prvious total+the new rating from the user
$new_rating=round($avg, 1); //rounding up the number to one's place //after this insert the updated records into the database
$insert="UPDATE productmaster SET Rating=$new_rating, TimesRated=$new_count WHERE ProductID=$id";
$insert_query=mysql_query($insert);
$previous = "product?id=".$id;
header('Location: '.$previous);
} else {
header('Location: index');
}