Jump to content

voting counter


corillo181

Recommended Posts

i was wokring on a code for a voting poll i thought this would work but it doesn't do nothing at all

is there something wrong with this code or i'm not even close?

[code]<a href="siteroot"?vote=yes">vote</a>[/code]

[code] <?php
$getcounter=mysql_query("SELECT counter FROM tra_music_top10 WHERE artist_id='$artist_id'")or die(mysql_error());

$count=mysql_fetch_array($getcounter);

if(!$count['counter']){
echo 0;
}else{
$i=$count['counter'];
if($_GET['vote']){
$voted=($i+1);
if(!$count){
$istvote=mysql_query("INSERT into tra_music_top10(artist_id,counter)VALUES('$arstist_id,'1')")or die (mysql_error());
}else{
$update=mysql_query("UPDATE tra_music_top10 SET counter='$voted'")or die(mysql_error());
}

}
}
?>[/code]
Link to comment
https://forums.phpfreaks.com/topic/31999-voting-counter/
Share on other sites

All you've done with this code is to set a variable with the contents of your query.  You haven't actually run the query.  Maybe change the last part of your code like this:

[code]
<?php
...
if (!$count) {
  $res_query = mysql_query("INSERT into tra_music_top10(artist_id,counter)VALUES('$arstist_id,'1')");
}
else {
  $res_query = mysql_query("UPDATE tra_music_top10 SET counter='$voted'");
}
if (!$res_query) {
  //there was an unsuccessful query, so you could display a custom message here or use mysql_error()
}
else {
  //you actually don't need the else, but you could use this for a "success" message
}

?>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/31999-voting-counter/#findComment-148512
Share on other sites

i tried that but it doens't wokr i tried it with a submit bottom but it doesn't work ither


[code]<form action="<?php $_SERVER['PHP_SELF'];?>" method="post">
      <label>
      <input name="Submit" type="submit" class="vote" value="Vote">
      </label>
    </form>[/code]

  <?php

$getcounter=mysql_query("SELECT counter FROM tra_music_top10 WHERE artist_id='$artist_id'")or die(mysql_error());

$count=mysql_fetch_array($getcounter);

if(!$count['counter']){
echo 0;
}else{
$i=$count['counter'];
echo $i;
}

if($_POST['Submit']){
$voted=($i+1);

$update=mysql_query("UPDATE tra_music_top10 SET counter='$voted'")or die(mysql_error());

if(!$update){
$newrecord=mysql_query("INSERT into tra_music_top10(artist_id,counter)VALUES('$artist_id','1')")or die(mysql_error());
}
}

?>
Link to comment
https://forums.phpfreaks.com/topic/31999-voting-counter/#findComment-148560
Share on other sites

the code seens to be working fine the only thing that does not wokr is inserting the new record if the record can't be update..

what i did wa si put a recor din and tried voting and it worked the problem seens to be in creating the record when voted for the first time.
Link to comment
https://forums.phpfreaks.com/topic/31999-voting-counter/#findComment-149083
Share on other sites

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.