corillo181 Posted December 27, 2006 Share Posted December 27, 2006 i was wokring on a code for a voting poll i thought this would work but it doesn't do nothing at allis 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 More sharing options...
trq Posted December 27, 2006 Share Posted December 27, 2006 Can you please indent your code? Most programmers indent there code in logical blocks, your is VERY hard to read. Link to comment https://forums.phpfreaks.com/topic/31999-voting-counter/#findComment-148504 Share on other sites More sharing options...
bljepp69 Posted December 27, 2006 Share Posted December 27, 2006 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 More sharing options...
corillo181 Posted December 28, 2006 Author Share Posted December 28, 2006 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 More sharing options...
redarrow Posted December 28, 2006 Share Posted December 28, 2006 $res_query = "UPDATE tra_music_top10 SET counter='$voted'+1 "; Link to comment https://forums.phpfreaks.com/topic/31999-voting-counter/#findComment-148658 Share on other sites More sharing options...
corillo181 Posted December 29, 2006 Author Share Posted December 29, 2006 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.