ryanfilard Posted October 11, 2011 Share Posted October 11, 2011 I am trying to make a rating system and this script is not working. $ratingget = $_REQUEST['star2']; mysql_select_db($database_news, $news); $query_ratingsys = "UPDATE news SET votes = votes +1 AND rating = rating +'$ratingget' WHERE id = '$id'"; $ratingsys = mysql_query($query_ratingsys, $news) or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/248861-why-wont-my-database-update/ Share on other sites More sharing options...
MasterACE14 Posted October 11, 2011 Share Posted October 11, 2011 are there any errors showing up? and is $_REQUEST['star2'] set? Quote Link to comment https://forums.phpfreaks.com/topic/248861-why-wont-my-database-update/#findComment-1277998 Share on other sites More sharing options...
ryanfilard Posted October 11, 2011 Author Share Posted October 11, 2011 No here is my form that submits. <form method="post" action="view.php?id=<?PHP echo $_REQUEST['id']; ?>"> <input name="star2" type="radio" class="star" value="1"/> <input name="star2" type="radio" class="star" value="2"/> <input name="star2" type="radio" class="star" value="3"/> <input name="star2" type="radio" class="star" value="4"/> <input name="star2" type="radio" class="star" value="5"/> <input type="hidden" name="formcheck" value="rating"> <input name="rate" type="submit" id="rate" value="Rate"> </form> Quote Link to comment https://forums.phpfreaks.com/topic/248861-why-wont-my-database-update/#findComment-1278001 Share on other sites More sharing options...
BigTime Posted October 11, 2011 Share Posted October 11, 2011 Hi Ryan # check for errors if (!$ratingsys) { echo("ERROR: " . mysql_error() . "\n$query_ratingsys\n"); $query_ratingsys = "UPDATE news SET votes = votes +1 AND rating = rating +'$ratingget' WHERE id = '$id'"; vote and rating you are trying to add to are not variables. Also, use a comma where the AND is Before I processed the update request I would define $votes, then add the +1 as $newvotes define $rating then add $ratingget as $newrating Then UPDATE news SET votes='$newvote',rating='$newrating' WHERE id = '$id'"; but Im a not very efficient hack and there is probably a smarter way Quote Link to comment https://forums.phpfreaks.com/topic/248861-why-wont-my-database-update/#findComment-1278038 Share on other sites More sharing options...
Buddski Posted October 11, 2011 Share Posted October 11, 2011 Is MySQL throwing any errors? My guess is you are trying to "add" a string to a, presumably, integer database column. Try something like this. $query_ratingsys = "UPDATE `news` SET `votes` = (`votes`+1) AND `rating` = (`rating`+$ratingget) WHERE `id` = '$id'"; Quote Link to comment https://forums.phpfreaks.com/topic/248861-why-wont-my-database-update/#findComment-1278061 Share on other sites More sharing options...
ryanfilard Posted October 11, 2011 Author Share Posted October 11, 2011 I used this $query_ratingsys = "UPDATE news SET votes=votes+'$newvote',rating=rating+'$ratingget' WHERE id = '$id'"; [code] It works now thank you. Quote Link to comment https://forums.phpfreaks.com/topic/248861-why-wont-my-database-update/#findComment-1278139 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.