Can someone advise why the results of the radio buttons do not post to my text file?
<?php $file='vote1.txt'; // if file doesn't exist, try to create it if(!file_exists($file)){ $fp=fopen($file,'w'); $close=fclose($fp); } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Test Radio Button Votes</title> </head> <body> <form action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" method="post"> <input type="radio" name="myvote" value="Yes">Yes<br> <input type="radio" name="myvote" value="No">No<br> <input type="radio" name="myvote" value="Maybe">Maybe<br> <input type="submit" name="submit" value="Submit"> </form> <?php // if the form has not been submitted if(!isset($_POST['submit'])) { $myvote=$_POST['myvote']; $fp=fopen("vote1.txt","a"); if(!$fp) { echo 'Error, the file could not be opened.'; exit; } fwrite($fp,$myvote."\n"); fclose($fp); } ?> </body> </html>
Thanks
looks like you are missing </form> i dont know if that would fix the problem, but maybe
Sorry, I just forgot to include it in my original post. It is there, so that's not the problem.
well, your form works for me as is, returns the radio value as expected.
are you able to write anything to the file using that code?
No, I get nothing with the above code.
For a test, I did change the fwrite line to read:
fwrite($fp,$myvote.'Date: '.date("M j,Y,g:i A")."\n");
The text file then showed the correct date, but still no value for the $myvote.
what do you get when you echo out $_POST['myvote']?
I get Zippo!! Nothing!! Therefore it seems obvious that the value of $myvote is just blank.
Now the question is why does my code work for you and not me?
just realized, shouldnt this:
if(!isset($_POST['submit']))
be
if(isset($_POST['submit']))
garblar, You just solved the mystery.
I also stuck in a checkbox as well as a textarea field and they all now get posted to the text file.
Many thanks.