Jump to content

Why Won't My Database Update?


ryanfilard

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.