Hello all,
I have a big problem... I want to put a php multiple-choice poll on my site. I found a great one, called "tapps poll" (let me say thanks to the guy who created it, Stephan). Regretfully I can't get into touch with him, so I have to ask my question here, and I hope someone of you will help me, because that poll is what I yearn for since 3 months now... I have never been that close to success.
In fact, the poll works great. But there is that problem: I can't get the IPs of the people who voted and the choices from the poll they picked at one table... I want to record the selected options in the "iplocks" table, but there only the IP of the voter plus the exact moment (year, month, date, hour, mniute) is recorded.
In the iplocks table there were 3 filelds: poll_id, ip, timestamp. I tried to add another one: option_id, where the selected options are recorded, and I had partly succeed, as ... only one of the options gets recorded there... So let me give you the code, to make myself clear:
// default action
function default_action()
{
$result = db_query("SELECT MAX(poll_id) AS max_poll_id FROM tapps_polls WHERE enabled='Y'");
$o = db_fetch_object($result);
if ($o->max_poll_id != NULL)
{
if (poll_over($o->max_poll_id)==TRUE)
{
print_results($o->max_poll_id);
echo "Voting for this poll is over.<br>\n";
}
else
{
print_vote_form($o->max_poll_id);
}
}
}
// counts the vote (make changes in db)
function count_vote($poll_id, $options)
{
global $HTTP_SERVER_VARS;
global $tapps_ip_locking;
// store data
foreach ($options as $option_id)
{
db_query("UPDATE tapps_votes SET counter=counter+1 WHERE poll_id=$poll_id AND option_id=$option_id");
}
[b]// lock ip
if (isset($tapps_ip_locking) && $tapps_ip_locking==TRUE)
{
$ip = $HTTP_SERVER_VARS['REMOTE_ADDR'];
db_query("INSERT INTO tapps_iplocks (poll_id,ip) VALUES($poll_id,'$ip')");[/b]
}
// give feedback
if (sizeof($options) > 1)
{
$c = $options[0]+1;
echo "Your votes for options $c";
for ($i=1;$i<sizeof($options)-1;$i++)
{
$c = $options[$i]+1;
echo ", $c";
}
$i = sizeof($options)-1;
$c = $options[$i]+1;
echo " and $c";
echo " have been counted.<br><br>\n";
} else
{
$c = $options[0]+1;
echo "Your vote for option $c has been counted.<br><br>\n";
}
// show updated results
print_results($poll_id);
}
So I changed
// lock ip
if (isset($tapps_ip_locking) && $tapps_ip_locking==TRUE)
{
$ip = $HTTP_SERVER_VARS['REMOTE_ADDR'];
db_query("INSERT INTO tapps_iplocks (poll_id,ip) VALUES($poll_id,'$ip')");
in that way:
// lock ip
if (isset($tapps_ip_locking) && $tapps_ip_locking==TRUE)
{
$ip = $HTTP_SERVER_VARS['REMOTE_ADDR'];
db_query("INSERT INTO tapps_iplocks (poll_id,ip,option_id) VALUES($poll_id,'$ip',$option_id)");
... and that's how I get recorded only one of the selections the voters have made. But as my poll is multiple choice as I told you, that is not enough... I really hope that you can help me get all the choices one has picked up in the table... that's so important for me and my site... I don't know how to do it 🙁. I will attach here the functions.inc.php file, if that will help you to help me, if you can and you want... 🙂 you can't imagine how grateful I'd be.
tapps poll site: http://su2.info/tapps/
Thank you all in advance for replying and helping!