Ellen67 Posted July 25, 2009 Share Posted July 25, 2009 I am trying to get form data go to a txt file when the submit button is hit.. Unfortunately the person that gave me the script to mess with won't around for a couple weeks.. I am just starting to get into php, so any help would be appreciated.. http://www.cloudswalk.com/oldies/requests/14kreq2.php is where I have it.. The code is : <?php if ($_SERVER['REQUEST_METHOD'] == 'POST') { $songtitle = $_POST['songtitle'] ; $artist = $_POST['artist'] ; $yourname = $_POST['yourname'] ; $dedication = $_POST['dedication'] ; $f=fopen("RequestList.txt","a"); fwrite($f,"$songtitle,$artist,$yourname,$dedication\r\n"); fclose($f); } ?> <center> <font face="Verdana" color=03045f> <table width="450px" border="3" bordercolor="#03045f" cellpadding="10"> <tr> <td> <form action="RequestList.txt" method="POST" name="inputform" id="inputform"> <b>Song Title:</b><br /> <input type="text" size="30" name="songtitle" /> <br /> <b>Artist(s):</b><br /> <input type="text" size="30" name="artist" /> <br /> <b>Your Name:</b><br /> <input type="text" size="30" name="yourname" /> <br /> <b>Dedication:</b><br /> <textarea cols="25" name="comments" rows="5"> </textarea> <br> <input type="submit" name="submit" value="save" /> </form> <br> </td> </tr> </table> </center> Thank you Ellen Quote Link to comment https://forums.phpfreaks.com/topic/167410-solved-form-info-to-text/ Share on other sites More sharing options...
.josh Posted July 25, 2009 Share Posted July 25, 2009 So what's the problem (other than not using code tags) ? Quote Link to comment https://forums.phpfreaks.com/topic/167410-solved-form-info-to-text/#findComment-882760 Share on other sites More sharing options...
AviNahum Posted July 25, 2009 Share Posted July 25, 2009 <?php if (isset($_POST['artist']) || isset($_POST['songtitle']) || isset($_POST['yourname'])) { $songtitle = $_POST['songtitle'] ; $artist = $_POST['artist'] ; $yourname = $_POST['yourname'] ; $dedication = $_POST['dedication'] ; $f=fopen("RequestList.txt","a"); fwrite($f,"".$songtitle.",".$artist.",".$yourname.",".$dedication."\r\n"); fclose($f); } ?> <center> <font face="Verdana" color=03045f> <table width="450px" border="3" bordercolor="#03045f" cellpadding="10"> <tr> <td> <form action="RequestList.txt" method="POST" name="inputform" id="inputform"> <b>Song Title:</b><br /> <input type="text" size="30" name="songtitle" /> <br /> <b>Artist(s):</b><br /> <input type="text" size="30" name="artist" /> <br /> <b>Your Name:</b><br /> <input type="text" size="30" name="yourname" /> <br /> <b>Dedication:</b><br /> <textarea cols="25" name="comments" rows="5"> </textarea> <br> <input type="submit" name="submit" value="save" /> </form> <br> </td> </tr> </table> </center> Quote Link to comment https://forums.phpfreaks.com/topic/167410-solved-form-info-to-text/#findComment-882761 Share on other sites More sharing options...
.josh Posted July 25, 2009 Share Posted July 25, 2009 The problem in the OP script (other than using deprecated stuff, but they still work), is a) your form action points to your text file. Change it to "" or name of the script (so it points to the script) b) you are using $_POST['description'] for your text area but you named your text area 'comments' so that value will not be written to your file unless you change that. Quote Link to comment https://forums.phpfreaks.com/topic/167410-solved-form-info-to-text/#findComment-882764 Share on other sites More sharing options...
Ellen67 Posted July 25, 2009 Author Share Posted July 25, 2009 Tyvm for the replies.. I've changed what you said but it's still not being written to the file. Quote Link to comment https://forums.phpfreaks.com/topic/167410-solved-form-info-to-text/#findComment-882768 Share on other sites More sharing options...
.josh Posted July 25, 2009 Share Posted July 25, 2009 post your current script with changes. I c/p'd your script, changed those 2 things, and it worked just fine for me. Quote Link to comment https://forums.phpfreaks.com/topic/167410-solved-form-info-to-text/#findComment-882770 Share on other sites More sharing options...
Ellen67 Posted July 25, 2009 Author Share Posted July 25, 2009 Sorry my bad, its been a log day.. Here it is: <?php $saving = $_REQUEST['saving']; if ($saving == 1){ $songtitle = $_POST['songtitle'] ; $artist = $_POST['artist'] ; $yourname = $_POST['yourname'] ; $dedication = $_POST['dedication'] ; $f=fopen("ReqList.txt","a"); fwrite($f,"".$songtitle.",".$artist.",".$yourname.",".$dedication."\r\n"); fclose($f); } ?> <center> <font face="Verdana" color=03045f> <table width="450px" border="3" bordercolor="#03045f" cellpadding="10"> <tr> <td><center> <form action="14kreq2.php" method="POST" name="inputform" id="inputform"> <b>Song Title:</b><br /> <input type="text" size="30" name="songtitle" /> <br /> <b>Artist(s):</b><br /> <input type="text" size="30" name="artist" /> <br /> <b>Your Name:</b><br /> <input type="text" size="30" name="yourname" /> <br /> <b>Dedication:</b><br /> <textarea cols="25" name="dedication" rows="5"> </textarea> <br> <input type="submit" name="submit" value="save" /> </form></center> <br> </td> </tr> </table> </center> Quote Link to comment https://forums.phpfreaks.com/topic/167410-solved-form-info-to-text/#findComment-882772 Share on other sites More sharing options...
mmarif4u Posted July 25, 2009 Share Posted July 25, 2009 <?php if (isset($_POST['submit']){ $songtitle = $_POST['songtitle'] ; $artist = $_POST['artist'] ; $yourname = $_POST['yourname'] ; $dedication = $_POST['dedication'] ; $f=fopen("ReqList.txt","a"); fwrite($f,"".$songtitle.",".$artist.",".$yourname.",".$dedication."\r\n"); fclose($f); } ?> <center> <font face="Verdana" color=03045f> <table width="450px" border="3" bordercolor="#03045f" cellpadding="10"> <tr> <td><center> <form action="" method="POST" name="inputform" id="inputform"> <b>Song Title:</b><br /> <input type="text" size="30" name="songtitle" /> <br /> <b>Artist(s):</b><br /> <input type="text" size="30" name="artist" /> <br /> <b>Your Name:</b><br /> <input type="text" size="30" name="yourname" /> <br /> <b>Dedication:</b><br /> <textarea cols="25" name="dedication" rows="5"> </textarea> <br> <input type="submit" name="submit" value="save" /> </form></center> <br> </td> </tr> </table> </center> Quote Link to comment https://forums.phpfreaks.com/topic/167410-solved-form-info-to-text/#findComment-882775 Share on other sites More sharing options...
.josh Posted July 25, 2009 Share Posted July 25, 2009 okay, so you've made other changes to your script, in addition to the ones suggested. You are now saving based on $_REQUEST['saving'] being 1. I do not see anywhere in your script that sets that to 1. As in, I do not see any elements in your form called 'saving'. Quote Link to comment https://forums.phpfreaks.com/topic/167410-solved-form-info-to-text/#findComment-882776 Share on other sites More sharing options...
Ellen67 Posted July 25, 2009 Author Share Posted July 25, 2009 ok got it now tyvm.. Just need the kick in the butt at the right time.. sry to pester.. Next time I let the boss "play & have fun" ! Again tyvm Quote Link to comment https://forums.phpfreaks.com/topic/167410-solved-form-info-to-text/#findComment-882794 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.