Jump to content

Recommended Posts

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());

Link to comment
https://forums.phpfreaks.com/topic/248861-why-wont-my-database-update/
Share on other sites

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>

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 :P

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'";

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.