chomedey Posted February 10, 2010 Share Posted February 10, 2010 Hello all, Does anyone know what is wrong with this? It's a rating update page, where it selects rating info from the database, adds to that info, and then updates it back to the db. There are no error messages - but my table is not being updated. Any help much appreciated. Cheers. Julian <?php //Call functions require_once('mds_fns.php'); //Call header do_html_header('Update Ratings'); do_top_display_bar(); do_second_display_bar(); //Connect to db $dbc = mysql_connect('localhost', 'root', 'One4Two'); mysql_select_db('mds'); if ((isset($_GET['id']) && is_numeric($_GET['id'])) && (isset($_GET['rate']) && is_numeric($_GET['rate']))) { $query = "SELECT total_rating, total_ratings, num_votes FROM deepshares WHERE entryID={$_GET['id']} LIMIT 1"; if ($r = mysql_query($query)) { while ($row = mysql_fetch_array($r)) { $total_rating = $row['total_rating']; $total_ratings = $row['total_ratings']; $num_votes = $row['num_votes']; $num_results = mysql_num_rows($r); } } $total_ratings = ($total_ratings+($_GET['rate'])); $num_votes = ($num_votes+1); $total_rating = ($total_ratings / $num_votes); $query = "UPDATE deepshares SET total_rating='$total_rating' AND num_votes='$num_votes' AND total_rating='$total_ratings' WHERE entryID={$_GET['id']} LIMIT 1"; if (@mysql_query($query)) { print '<p>Thankyou for your vote. The rating for this entry has been updated.</p>'; } else { print '<p>There was a problem updating the record.</p>'; } } do_html_footer(); ?> Link to comment https://forums.phpfreaks.com/topic/191679-help-with-updating-tables/ Share on other sites More sharing options...
Orionsbelter Posted February 10, 2010 Share Posted February 10, 2010 Are all the fields the same in the database as they are in your PHP script? Link to comment https://forums.phpfreaks.com/topic/191679-help-with-updating-tables/#findComment-1010350 Share on other sites More sharing options...
chomedey Posted February 10, 2010 Author Share Posted February 10, 2010 I believe so. I thought something may have gone wrong there so I dropped them and added them again to make sure. Do they have to be in the same order as in the query command? Thanks. Julian Link to comment https://forums.phpfreaks.com/topic/191679-help-with-updating-tables/#findComment-1010352 Share on other sites More sharing options...
chomedey Posted February 10, 2010 Author Share Posted February 10, 2010 The db fields are set as INT NOT NULL. That's OK, no? Link to comment https://forums.phpfreaks.com/topic/191679-help-with-updating-tables/#findComment-1010354 Share on other sites More sharing options...
sader Posted February 10, 2010 Share Posted February 10, 2010 will there be any output if u will change code a bit like this if ((isset($_GET['id']) && is_numeric($_GET['id'])) && (isset($_GET['rate']) && is_numeric($_GET['rate']))) { //code } else { echo "Wrong GET parameters"; } Link to comment https://forums.phpfreaks.com/topic/191679-help-with-updating-tables/#findComment-1010359 Share on other sites More sharing options...
chomedey Posted February 10, 2010 Author Share Posted February 10, 2010 It output Thankyou for your vote. The rating for this entry has been updated. I'm pretty sure it's in the updating, and I've recreated the complete table now and still nothing. The weird thing is that it always says "Thankyou for your vote" but then it hasn't actually sent the data (or it has but it hasn't registered it). Even when I ascribe integers to the fields it doesn't seem to take them. I'm flummoxed. Code used was: //Connect to db $dbc = mysql_connect('localhost', 'root', 'One4Two'); mysql_select_db('mds'); //if ((isset($_GET['id']) && is_numeric($_GET['id'])) && (isset($_GET['rate']) && is_numeric($_GET['rate']))) if ((isset($_GET['id']) && is_numeric($_GET['id'])) && (isset($_GET['rate']) && is_numeric($_GET['rate']))) { $query = "SELECT total_rating, total_ratings, num_votes FROM deepshares WHERE entryID={$_GET['id']} LIMIT 1"; if ($r = mysql_query($query)) { while ($row = mysql_fetch_array($r)) { $total_rating = $row['total_rating']; $total_ratings = $row['total_ratings']; $num_votes = $row['num_votes']; $num_results = mysql_num_rows($r); } } else { echo "Wrong GET parameters"; } Link to comment https://forums.phpfreaks.com/topic/191679-help-with-updating-tables/#findComment-1010365 Share on other sites More sharing options...
chomedey Posted February 10, 2010 Author Share Posted February 10, 2010 Sorry - should have included rest of code otherwise output makes no sense: $total_ratings = ($total_ratings+($_GET['rate'])); $num_votes = ($num_votes+1); $total_rating = ($total_ratings / $num_votes); $query = "UPDATE deepshares SET total_rating='$total_rating' AND num_votes='$num_votes' AND total_rating='$total_ratings' WHERE entryID={$_GET['id']} LIMIT 1"; if (@mysql_query($query)) { print '<p>Thankyou for your vote. The rating for this entry has been updated.</p>'; } else { print '<p>There was a problem updating the record.</p>'; } } do_html_footer(); ?> Link to comment https://forums.phpfreaks.com/topic/191679-help-with-updating-tables/#findComment-1010368 Share on other sites More sharing options...
sader Posted February 10, 2010 Share Posted February 10, 2010 what about change it a bit like this $query = "UPDATE deepshares SET total_rating='$total_rating' AND num_votes='$num_votes' AND total_rating='$total_ratings' WHERE entryID={$_GET['id']} LIMIT 1"; echo $query; if (@mysql_query($query)) { //... } Link to comment https://forums.phpfreaks.com/topic/191679-help-with-updating-tables/#findComment-1010372 Share on other sites More sharing options...
chomedey Posted February 10, 2010 Author Share Posted February 10, 2010 It outputs this: UPDATE deepshares SET total_rating='2' AND num_votes='1' AND total_rating='2' WHERE entryID=2 LIMIT 1 Thankyou for your vote. The rating for this entry has been updated. Link to comment https://forums.phpfreaks.com/topic/191679-help-with-updating-tables/#findComment-1010374 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.