lesliegy Posted January 12, 2010 Share Posted January 12, 2010 First, I hope this is in the right spot... I have a small piece of code that's driving me nuts LOL. Was wondering if someone here might be able to help. I'm trying to make it where members can only vote every 24 hours on various pictures. Basically i'm trying to get a countup that counts to 24 hours, once the 24 time period is met the member can vote again. can someone please tell me what I'm missing... many thanks in advance for any advice! THE CODE:::: $uvote= mysql_query("SELECT time FROM $tab[membervote] WHERE vote='$image[id]' AND member='$member[memberid]';"); <? if($uvote[time] > $time){?> You can vote again in:<br> <font color="red"><?=countup($uvote[time]+84600)?></font> <? }?> <? if($uvote[time] < $time){?> <form action="voteonpic.php?tru=<?=$tru?>" method="post" target="_blank"> <input type="hidden" name="siteid" value="<?=$image[id]?>"> <input type="submit" class="button" name="votenow" value="Vote now"> </form> Link to comment https://forums.phpfreaks.com/topic/188219-need-a-little-help-with-the-following-code/ Share on other sites More sharing options...
greatstar00 Posted January 12, 2010 Share Posted January 12, 2010 84600<< it isnt always 86400 if u want them can vote again at 12:AM, and they come back at 12PM, this isnt 86400 and what if they voted at 12AM, come back once at 1AM?, or come back 2nd time at 12PM? so, use currenttime-votetime+86400 u missed the script to update the voted time, or insert it, i recommend use replace mysql command and a function, at the voting script, to send error when it isnt 24 hr Link to comment https://forums.phpfreaks.com/topic/188219-need-a-little-help-with-the-following-code/#findComment-993703 Share on other sites More sharing options...
Catfish Posted January 12, 2010 Share Posted January 12, 2010 For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error. You need to use a mysql_fetch_ function on $uvote and you should really verify if $uvote SELECT was sucessful: if ($uvote = mysql_query("SELECT time FROM $tab[membervote] WHERE vote='$image[id]' AND member='$member[memberid]';")) { if ($uvoteData = mysql_fetch_assoc($uvote)) { if ($uvoteData['time'] > $time) { ... // etc } } else print('Could not fetch utime data from database result.<br/>'."\n"); } else print('Could not SELECT utime from datbase. Error given: '.mysql_error().'<br/>'."\n"); See: http://au.php.net/manual/en/function.mysql-fetch-assoc.php http://au.php.net/manual/en/function.mysql-fetch-array.php http://au.php.net/manual/en/function.mysql-fetch-row.php http://au.php.net/manual/en/function.mysql-query.php http://au.php.net/manual/en/function.mysql-error.php Link to comment https://forums.phpfreaks.com/topic/188219-need-a-little-help-with-the-following-code/#findComment-993706 Share on other sites More sharing options...
lesliegy Posted January 12, 2010 Author Share Posted January 12, 2010 Wow... you guys are fast!! Thanks so much for the input/help, I will try making the changes and post update! Thanks Link to comment https://forums.phpfreaks.com/topic/188219-need-a-little-help-with-the-following-code/#findComment-993715 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.