Creig Posted June 18, 2013 Share Posted June 18, 2013 Hello. I have been trying to get my php poll to show results if user has already voted, I have been trying for 2 months now and every thing i try doesnt work so i need help please, Can any one help me with this? Ill post what i have scripted so farThe poll.php//<?php?><html><head><script>function getVote(int){if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safarixmlhttp=new XMLHttpRequest();}else{// code for IE6, IE5xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}xmlhttp.onreadystatechange=function(){if (xmlhttp.readyState==4 && xmlhttp.status==200){document.getElementById("poll").innerHTML=xmlhttp.responseText;}}xmlhttp.open("GET","mypoll/poll_vote.php?vote="+int,true);xmlhttp.send();}</script></head><body><div id="poll"><h3>Do you like PHP and AJAX so far?</h3><form>Yes:<input type="radio" name="vote" value="0" onClick="getVote(this.value)"><br>No:<input type="radio" name="vote" value="1" onClick="getVote(this.value)"></form></div></body>And then the poll_vote.php//<?phpsetcookie("poll","1",time()+86400*30);if($_COOKIE['poll'] == 1){die ("you've already voted in this poll");}ELSE{echo 'Thank you for your vote';}$vote = $_REQUEST['vote'];//get content of textfile$filename = "poll_result.txt";$content = file($filename);//put content in array$array = explode("||", $content[0]);$yes = $array[0];$no = $array[1];if ($vote == 0){$yes += 1;}if ($vote == 1){$no += 1;}//insert votes to txt file$insertvote = $yes."||".$no;$fp = fopen($filename,"w");fputs($fp,$insertvote);fclose($fp);?><h2>Results: Do you prefer using contractor or do it your self?</h2><table><tr><td>contractor:</td><td><img src="mypoll/poll.gif"width='<?php echo(100*round($yes/($no+$yes),2)); ?>'height='20'><?php echo(100*round($yes/($no+$yes),2)); ?>%</td></tr><tr><td>myself:</td><td><img src="mypoll/poll.gif"width='<?php echo(100*round($no/($no+$yes),2)); ?>'height='20'><?php echo(100*round($no/($no+$yes),2)); ?>%</td></tr><td>Number of votes:</td><td><?php echo ($yes+$no); ?></td></tr></table>Thank you for any help can give, Creig Link to comment https://forums.phpfreaks.com/topic/279332-php-poll/ Share on other sites More sharing options...
ginerjm Posted June 19, 2013 Share Posted June 19, 2013 Would love to help you out. However, you could make our help easier to obtain if you asked a direct question and pointed us to the code you suspect is the problem. This whole script can't be your problem, so do your debugging and show us what you've found. Link to comment https://forums.phpfreaks.com/topic/279332-php-poll/#findComment-1436834 Share on other sites More sharing options...
Irate Posted June 19, 2013 Share Posted June 19, 2013 It is a very good practice to wrap all code in [ code ] [ /code ] tags (without the spaces so that it gets parsed correctly). Inline code which doesn't take up much space can be wrapped in [ ic ] [ /ic ] tags (again, without the spaces so that it gets parsed). Examples. // this is a demonstration of the code tag // it features a few comments to make its purpose clear $ic = 'this is some short inline code'; Link to comment https://forums.phpfreaks.com/topic/279332-php-poll/#findComment-1436854 Share on other sites More sharing options...
Creig Posted June 25, 2013 Author Share Posted June 25, 2013 Hello,, Ill try to be as specific as i can,, I am trying to use the code above as i have learned from w3 schools and i am trying to figure out how i can add a text link on my poll to linnk to the results without actualy adding another value to the total amount of votes.. Just a link to the results. I am a new programmer and i love trying to learn but as you know examples are very helpfull. Any help is greatly appreciated Link to comment https://forums.phpfreaks.com/topic/279332-php-poll/#findComment-1437802 Share on other sites More sharing options...
Creig Posted June 26, 2013 Author Share Posted June 26, 2013 You all really suck at php. You couldnt even help. I mean really. PHP help?? haha Link to comment https://forums.phpfreaks.com/topic/279332-php-poll/#findComment-1437901 Share on other sites More sharing options...
Creig Posted June 26, 2013 Author Share Posted June 26, 2013 It is a very good practice to wrap all code in [ code ] [ /code ] tags (without the spaces so that it gets parsed correctly). Inline code which doesn't take up much space can be wrapped in [ ic ] [ /ic ] tags (again, without the spaces so that it gets parsed). Examples. // this is a demonstration of the code tag // it features a few comments to make its purpose clear $ic = 'this is some short inline code'; meat head Link to comment https://forums.phpfreaks.com/topic/279332-php-poll/#findComment-1437902 Share on other sites More sharing options...
ginerjm Posted June 26, 2013 Share Posted June 26, 2013 We would have helped you if you had helped us by pointing out where you thought the problem was occurring. You were asked. You refused. Who sux now? Go home, grow up, learn to read and write better English. Come back as an adult. Link to comment https://forums.phpfreaks.com/topic/279332-php-poll/#findComment-1437961 Share on other sites More sharing options...
trq Posted June 26, 2013 Share Posted June 26, 2013 We would have helped you if you had helped us by pointing out where you thought the problem was occurring. You were asked. You refused. Who sux now? Go home, grow up, learn to read and write better English. Come back as an adult. Please don't feed the trolls. Link to comment https://forums.phpfreaks.com/topic/279332-php-poll/#findComment-1437963 Share on other sites More sharing options...
Recommended Posts