phpBB problem! PHP help needed!

They have: 344 posts

Joined: Jun 2002

Hi guys!

Oh and btw this is a mod which works in conjuction with a "guest voting" mod to track the IP of a guest voter and stop them from voting more than once. This is not my code but the person wants it finished, so I thought I may as well ask you as he doesn't know what to do. What he wants is a way to display an error message, and return to to results of the poll when the customer has already voted.

He thinks that the "message_die" function could do this in place of :

require('http://www.wizardsandwars.com/already_voted.php'); '

but needs some people with knowledge of this to help him out.

His code is:

//// Begin IP track hack ///

   // Need to change this to match the poll ID in the forum
   $pollid= $HTTP_POST_VARS['vote_id']; 
   
   $ip = getenv("REMOTE_ADDR");
   $past = time()-90800;
   $votevalid=1;
   $query="DELETE FROM phesis_poll_check WHERE time < ".$past;
   $db->sql_query($query);
   
   
   $sql="SELECT ip FROM phesis_poll_check WHERE ip='".$ip."' and pollid='".$pollid."'";
   $result = $db->sql_query($sql);
   $post_info = $db->sql_fetchrow($result);
   
   $ips=$post_info['ip'];
   $ctime = time();
   if ($ip == $ips) {
     $votevalid = 0;
     require('http://www.wizardsandwars.com/already_voted.php');
     exit();
   } else {
     $query="INSERT INTO phesis_poll_check (ip, time, pollid) VALUES ('".$ip."', '".$ctime."' , '"."2"."')";
     $db->sql_query($query);
     $votevalid = 1;
   }
   
   //// End IP track hack ////
'

Hope you can help! Thanks!

He has: 296 posts

Joined: May 2002

Sure, you can just use

die("Your message here");
'

and it should work. You won't need exit(); Or you can use exit the same way as die.

They have: 344 posts

Joined: Jun 2002

and I put this into posting.php where it says:

else if ( $mode == 'vote' ) right? Just slightly after that?

They have: 344 posts

Joined: Jun 2002

No it doesn't work. What the script wants to do is to make sure that a user cannot vote again after submitting the vote. It wants to display the voting results. How can I do this?

He has: 296 posts

Joined: May 2002

Ahhhh, I thought it would just display a message. I highly doubt you could do that with die() or exit().

They have: 344 posts

Joined: Jun 2002

Right well the current code is:

//// Begin IP track hack ///

   // Need to change this to match the poll ID in the forum
   $pollid= $HTTP_POST_VARS['vote_id']; 
   
   $ip = getenv("REMOTE_ADDR");
   $past = time()-90800;
   $votevalid=1;
   $query="DELETE FROM phesis_poll_check WHERE time < ".$past;
   $db->sql_query($query);
   
   
   $sql="SELECT ip FROM phesis_poll_check WHERE ip='".$ip."' and pollid='".$pollid."'";
   $result = $db->sql_query($sql);
   $post_info = $db->sql_fetchrow($result);
   
   $ips=$post_info['ip'];
   $ctime = time();
   if ($ip == $ips) {
     $votevalid = 0;
     //require('http://www.wizardsandwars.com/already_voted.php');
     exit();
       if ( $votevalid == 0 ) {
         header("Location: " . append_sid("already_voted.$phpEx?redirect=viewtopic.$phpEx", true));
       } else {
     $query="INSERT INTO phesis_poll_check (ip, time, pollid) VALUES ('".$ip."', '".$ctime."' , '"."2"."')";
     $db->sql_query($query);
     $votevalid = 1;
   }
   
   //// End IP track hack ////
'

It is placed inside posting.php here:

$message = $lang['Vote_cast'];
}
else
{
$message = $lang['Already_voted'];
}
//// Begin IP track hack ///

   // Need to change this to match the poll ID in the forum
   $pollid= $HTTP_POST_VARS['vote_id']; 
   
   $ip = getenv("REMOTE_ADDR");
   $past = time()-90800;
   $votevalid=1;
   $query="DELETE FROM phesis_poll_check WHERE time < ".$past;
   $db->sql_query($query);
   
   
   $sql="SELECT ip FROM phesis_poll_check WHERE ip='".$ip."' and pollid='".$pollid."'";
   $result = $db->sql_query($sql);
   $post_info = $db->sql_fetchrow($result);
   
   $ips=$post_info['ip'];
   $ctime = time();
   if ($ip == $ips) {
     $votevalid = 0;
     //require('http://www.wizardsandwars.com/already_voted.php');
     exit();
       if ( $votevalid == 0 ) {
         header("Location: " . append_sid("already_voted.$phpEx?redirect=viewtopic.$phpEx", true));
       } else {
     $query="INSERT INTO phesis_poll_check (ip, time, pollid) VALUES ('".$ip."', '".$ctime."' , '"."2"."')";
     $db->sql_query($query);
     $votevalid = 1;
   }
   
   //// End IP track hack ////

}
else
{
$message = $lang['No_vote_option'];
}
'

But now I have noticed that it registers the vote but it doesn't come up with a page saying that you have voted. Why is this? Could you get it to come up with a page with the results to stop guests from voting repetively?

They have: 344 posts

Joined: Jun 2002

Right I have added this code, replacing the code given by Bummer.

{
message_die(GENERAL_ERROR, 'You have voted more than once in the poll');
}

$sql="SELECT vd.topic_id
FROM " . TOPICS_TABLE . " vd, " . TOPICS_WATCH_TABLE . " vr
WHERE vd.topic_id = $topic_id;

} else {
'

I now get a

Parse error: parse error, unexpected T_STRING in /home/virtual/site21/fst/var/www/html/board/posting.php on line 490

This is:

$query="INSERT INTO phesis_poll_check (ip, time, pollid)
VALUES ('".$ip."', '".$ctime."' , '"."2"."')";
'

and the code i have suggested above is directly above this. Can you solve this error for me?

Busy's picture

He has: 6,151 posts

Joined: May 2001

the error looks like its "."2"." (to many quotes), try change it to ".2."

He has: 296 posts

Joined: May 2002

No, just make it '2' without the "."s. They aren't needed.

They have: 344 posts

Joined: Jun 2002

So the code should be:

$query="INSERT INTO phesis_poll_check (ip, time, pollid) VALUES ('".$ip."', '".$ctime."' , '".'2'."')";'

Or

$query="INSERT INTO phesis_poll_check (ip, time, pollid) VALUES (".$ip.", ".$ctime." , ".2.")";'

He has: 296 posts

Joined: May 2002

should be

$query="INSERT INTO phesis_poll_check (ip, time, pollid)
VALUES ('".$ip."', '".$ctime."' , '2')";
'

[James Logsdon]

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.