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.
$difference = $_SESSION['id'] - count($rated);
$rated = implode(',',$rated);
while ($difference >= 0)
$rated .= "0,";
$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)
$ratingsadded += $rating;
$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']);
Whilst Rajdeep has deleted his answers, I intended on responding with the following:
Thank you very much, whilst your answer was a tiny bit off, it pointed out the problem I had- I was using $user as a foreach key value and as a query result.
I have found the problem and it was a case of simple stupidity and assigning variables atop of other variables.
I am sorry for putting you all through the trouble of attempting to assist me for this.