I am tryin to code for a poll that allows people to read a review and the vote yes or no as to whether it was helpful. There are yes and no .txt file allocated for each review. The form should read the file and add one onto it. then using cookies it refuses to allow the person to vote again.
Have coded it but it doesn't work and connot work out why, wanted to know how you may have coded it, I am having problems doing the formaction due to the way in which my navigation works, wondered whether you guys knew of any where where I could get this style of script and edit to suit my needs.
Lastly this is the first time I have used cookies but they all appear to be right.
So basically where can I find a poll that is cookie regulated( ie if there is a cookie of the same name as the review it should not display otion to vote)
PHP sofar looks like this:
Code: Select all
<?php
function no(){
$counter_file = 'php/form_data/votes/'.$review.'_no.txt';
if (file_exists($counter_file)){
print("$counter said no.");}else{
print("no previous results");
}}
function yes(){
$counter_file = 'php/form_data/votes/'.$review.'_yes.txt';
if (file_exists($counter_file)){
print("$counter said yes.");}else{
print("no previous results");
}}
createform(){
print("<center><table cellspacing=0 cellpadding=0 width=540 border=0>
<TR><TD>");
yes();
print(" - ");
no();
print("</TD></TR>
<FORM action="?id=vote_handler" method=post name=review_n>
<TR><TD>Was this Review Helpful:</TD></TR>
<TR><TD>YES<input type=radio name=yes> NO<INPUT TYPE=RADIO Name=no></TD></TR>
<TR><TD><input type=hidden name=beensubmitted value=true></TD></TR>
<TR><TD><CENTER><INPUT TYPE=SUBMIT value=Submit! name=Submit></TABLE>");}
if($_COOKIE[$review]){
print("<center><table cellspacing=0 cellpadding=0 width=540 border=0>
<TR><TD>Sorry You Have Already Voted For This Review</TD></TR></TABLE>");
}else{
createform();
}
?>Code: Select all
<?php
if($beensubmitted){
if($yes){
$counter_file = 'php/form_data/votes/'.$review.'_yes.txt';
if (file_exists($counter_file)){
$counter = file_get_contents($counter_file);
if (is_numeric($counter)){$counter++;}else{$counter = 0;}
$fp = fopen($counter_file, 'w');
fwrite($fp, $counter);
fclose($fp);}
setcookie($review, "", 3600);
print("Thank you for your time your entry has been submitted");}
if($no){
$counter_file = 'php/form_data/votes/'$review.'_no.txt';
if (file_exists($counter_file)){
$counter = file_get_contents($counter_file);
if (is_numeric($counter)){$counter++;}else{$counter = 0;}
$fp = fopen($counter_file, 'w');
fwrite($fp, $counter);
fclose($fp);}
setcookie($review, "", 3600);
print("Thank you for your time your entry has been submitted");}
?>