Update database based on radio button value

Im trying to create a rating system for a website. Im able to retrieve the items from the database and display 5 radio buttons under each item. The 5 radio buttons have the values 1 to 5.

Im trying to update the rating of each item based on the value of the radio button thats selected.

I have the following code:

<?php
$results = $mysqli->query("SELECT * FROM programmes ORDER BY ProgrammeName ASC");
if ($results) { 
     $i=0;
     echo '<table><tr>';

     echo '<br/>';
     echo '<br/>';

     while($obj = $results->fetch_object())
    {   
        echo '<td>';
        echo '
'; echo ''; echo "ProgrammeID)."\" />"; echo '
Image.'">
'; echo '

'.$obj->ProgrammeName.'

'; echo '

'.$obj->Rating.'

'; echo '<input type="radio" class="rating-input" id="rate" name="rate" value="1">'; echo '<input type="radio" class="rating-input" id="rate" name="rate" value="2">'; echo '<input type="radio" class="rating-input" id="rate" name="rate" value="3">'; echo '<input type="radio" class="rating-input" id="rate" name="rate" value="4">'; echo '<input type="radio" class="rating-input" id="rate" name="rate" value="5">'; echo '<br/>'; echo '</form>'; echo '</div>'; echo '</td>'; $i++; if ($i == 5 OR $i == 10) { echo '</tr><tr>'; } } echo '</tr></table>'; } if(isset($_POST['rate'])){ $newRating = $_POST['rate']; $ID = $_POST['progID']; $upsql = "UPDATE programmes SET Rating = Rating + $newRating WHERE ProgrammeID='$ID'"; $stmt = $mysqli->prepare($upsql); $stmt->execute(); } ?>

All of the code works fine except for the Update statement where im adding to the current rating that is already stored in the database.

Can someone help me on how to fix this issue

Thanks!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s