Jump to content

Need a little help with the following code.


lesliegy

Recommended Posts

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>

 

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

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

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.