vmars Posted July 14, 2011 Share Posted July 14, 2011 HI! I am making a php poll without a database but with a txt file. I have two php scripts (one with the poll, the other with the results) and I am having trouble getting one to talk to the other. Any help is appreciated! Here they are: poll.php <html> <head> <title>POLL!</title> <?PHP $selected_radio = $_POST['album']; print $selected_radio; if (isset($_POST['Submit1'])) { $selected_radio = $_POST['album']; print $selected_radio; } ?> </head> <body> <h1>Cats or Dogs?</h1> <Form name ="form1" Method ="Post" ACTION ="poll.php"> <Input type = 'Radio' Name ='album' value= 'cats'>Cats <Input type = 'Radio' Name ='album' value= 'dogs'>Dogs <P> <Input type = "Submit" Name = "Submit1" Value = "Vote!"> </FORM> <?PHP $usea_status = 'unchecked'; $useb_status = 'unchecked'; if (isset($_POST['Submit1'])) { $selected_radio = $_POST['album']; if ($selected_radio == 'cats') { $cats_status = 'checked'; } elseif ($selected_radio == 'dogs') { $dogs_status = 'checked'; } } ?> </body> </html> ----------- poll2.php <?php $vote = $_REQUEST['vote']; //get content of textfile $filename = "poll.txt"; $content = file($filename); //put content in array $array = explode("||", $content[0]); $yes = $array[0]; $no = $array[1]; if ($vote == 0) { $yes = $yes + 1; } if ($vote == 1) { $no = $no + 1; } //insert votes to txt file $insertvote = $yes."||".$no; $fp = fopen($filename,"w"); fputs($fp,$insertvote); fclose($fp); ?> <h2>Result:</h2> <table> <tr> <td>Cats:</td> <td> <?php echo(100*round($yes/($no+$yes),2)); ?>% </td> </tr> <tr> <td>Dogs:</td> <td> <?php echo(100*round($no/($no+$yes),2)); ?>% </td> </tr> </table> Quote Link to comment https://forums.phpfreaks.com/topic/241949-php-poll/ Share on other sites More sharing options...
btherl Posted July 14, 2011 Share Posted July 14, 2011 One of those is a cats/dogs poll and the other is a yes/no poll. How do you want them to communicate? Quote Link to comment https://forums.phpfreaks.com/topic/241949-php-poll/#findComment-1242589 Share on other sites More sharing options...
vmars Posted July 14, 2011 Author Share Posted July 14, 2011 sorry, changed the poll topic and not all of the words. easily fixable! this still won't make em "talk" though. Quote Link to comment https://forums.phpfreaks.com/topic/241949-php-poll/#findComment-1242671 Share on other sites More sharing options...
vmars Posted July 14, 2011 Author Share Posted July 14, 2011 poll2.php updated. still needing help: <?php $vote = $_REQUEST['vote']; //get content of textfile $filename = "poll.txt"; $content = file($filename); //put content in array $array = explode("||", $content[0]); $yes = $array[0]; $no = $array[1]; if ($vote == 0) { $cats = $cats + 1; } if ($vote == 1) { $dogs = $dogs + 1; } //insert votes to txt file $insertvote = $cats."||".$dogs; $fp = fopen($filename,"w"); fputs($fp,$insertvote); fclose($fp); ?> <h2>Result:</h2> <table> <tr> <td>Cats:</td> <td> <?php echo(100*round($cats/($dogs+$cats),2)); ?>% </td> </tr> <tr> <td>Dogs:</td> <td> <?php echo(100*round($dogs/($dogs+$cats),2)); ?>% </td> </tr> </table> Quote Link to comment https://forums.phpfreaks.com/topic/241949-php-poll/#findComment-1242858 Share on other sites More sharing options...
btherl Posted July 15, 2011 Share Posted July 15, 2011 I think you need poll2.php as the action of the form in poll.php. And check that the name of the input element is the name you are looking for in $_REQUEST, which in this case is "album", not "vote". Quote Link to comment https://forums.phpfreaks.com/topic/241949-php-poll/#findComment-1242908 Share on other sites More sharing options...
Alex Posted July 15, 2011 Share Posted July 15, 2011 In the future please use or tags; it makes it much easier to read your code. Quote Link to comment https://forums.phpfreaks.com/topic/241949-php-poll/#findComment-1242914 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.