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
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
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
Share on other sites

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.