I have been working on a website and recently added some changes to it, despite attempting to comment out said changes, my UPDATE query is not working- I have been attempting to figure out why for the last 3ish hours to no avail.
if (isset($_POST['submit']))
{
if (count($rated)<$_SESSION['id'])
{
$difference = $_SESSION['id'] - count($rated);
$rated = implode(',',$rated);
while ($difference >= 0)
{
$rated .= "0,";
$difference--;
}
$rated = explode(',',$rated);
}
$rated[$_SESSION['id']] = $_POST['rating'];
$ratings = 0;
$ratingsadded = 0;
foreach ($rated as $user => $rating)
{
if ($rating != 0)
{
$query = $db->prepare("SELECT id, active FROM accounts WHERE id = :id");
$query->execute(array('id' => $user));
$useractive = $query->fetch();
if ($useractive['active'] == 1 || $user == 0 || $user == 50)
{
$ratings++;
$ratingsadded += $rating;
}
else
{
$rated[$user] = 0;
}
}
}
$ratingtotal = $ratingsadded / $ratings;
$query = $db->prepare("UPDATE accounts SET rating = :rating, rated = :rated WHERE id = :id");
$query->execute(array('rating' => $ratingtotal, 'rated' => implode(",",$rated), 'id' => $user['id']));
header('Location: ?user=' . $_GET['user']);
}
Note: The query at the very end is the one I am referring to.
Secondary note: I know that there are quite a few inefficiencies in my code.
Full code: http://pastebin.com/ybb71U6k