Jump to content

Creig

Members
  • Posts

    4
  • Joined

  • Last visited

Creig's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Creig

    PHP Poll

    You all really suck at php. You couldnt even help. I mean really. PHP help?? haha
  2. Creig

    PHP Poll

    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
  3. Creig

    PHP Poll

    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 far The poll.php //<?php ?> <html> <head> <script> function getVote(int) { if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=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 //<?php setcookie("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
×
×
  • 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.