spillage Posted April 22, 2008 Share Posted April 22, 2008 Hi this is all new to me and cannot spot my mistake here so hoping someone can point out the obvious. Why will this not send to my .txt file???. $cust is been posted from an email. <form action="http://localhost/mail01.php" method="post"> <table border="0" align="left"> <tr> <td>Friends Email: </td> <td align="left"><input type="text" name="address" size=40 maxlength=50></td> </tr> <td colspan=2 align=center><input type=submit value="Send Details"></td> </tr> <?php $DOCUMENT_ROOT=$_SERVER['DOCUMENT_ROOT']; $cust=$_POST["email"]; $friend=$_POST["address"]; $output= "\t".$friend."\n"; echo "Your email is: ".$cust; @ $fp= fopen ("DOCUMENT_ROOT/rcfriend.txt",'a+'); fwrite ($fp,$output, strlen($output)); fclose($fp); ?> Thanks Mark Link to comment https://forums.phpfreaks.com/topic/102394-solved-writing-to-file/ Share on other sites More sharing options...
DarkWater Posted April 22, 2008 Share Posted April 22, 2008 <?php $DOCUMENT_ROOT=$_SERVER['DOCUMENT_ROOT']; $cust=$_POST["email"]; $friend=$_POST["address"]; $output= "\t".$friend."\n"; echo "Your email is: ".$cust; @ $fp= fopen ("$DOCUMENT_ROOT/rcfriend.txt",'a+'); fwrite ($fp,$output, strlen($output)); fclose($fp); ?> You missed a $. Does it echo the Your email is: part? Link to comment https://forums.phpfreaks.com/topic/102394-solved-writing-to-file/#findComment-524291 Share on other sites More sharing options...
spillage Posted April 22, 2008 Author Share Posted April 22, 2008 Hi Dark Water. Thanks it would have taken me all night to spot that one and has sorted out that problem. Yes it does echo 'your email' although when you submit the page this then disapears which looks a bit cacky would you have any ideas on that. Trying to find out if I can $_POST into a form so that it would always loop when the submit button is clicked. Thanks Mark Link to comment https://forums.phpfreaks.com/topic/102394-solved-writing-to-file/#findComment-524300 Share on other sites More sharing options...
DarkWater Posted April 22, 2008 Share Posted April 22, 2008 <?php if (isset($_POST['submitted']) { $DOCUMENT_ROOT=$_SERVER['DOCUMENT_ROOT']; $cust=$_POST["email"]; $friend=$_POST["address"]; $output= "\t".$friend."\n"; echo "Your email is: ".$cust; @ $fp= fopen ("$DOCUMENT_ROOT/rcfriend.txt",'a+'); fwrite ($fp,$output, strlen($output)); fclose($fp); } ?> <form action="http://localhost/mail01.php" method="post"> <table border="0" align="left"> <tr> <td>Friends Email: </td> <td align="left"><input type="text" name="address" size=40 maxlength=50></td> </tr> <input type="hidden" name="submitted" value="true" /> <td colspan=2 align=center><input type=submit value="Send Details"></td> </tr> The script sends it back to itself and handles the data, right? This is a better version if that's the case. Link to comment https://forums.phpfreaks.com/topic/102394-solved-writing-to-file/#findComment-524308 Share on other sites More sharing options...
spillage Posted April 22, 2008 Author Share Posted April 22, 2008 When running this I get Parse error: syntax error, unexpected '{' in C:\wamp\www\mail01.php on line 19 The $cust=$_POST["email"]; comes from another html page (email). This variable is the one that I would like to loop within this code. Cheers. Link to comment https://forums.phpfreaks.com/topic/102394-solved-writing-to-file/#findComment-524332 Share on other sites More sharing options...
DarkWater Posted April 22, 2008 Share Posted April 22, 2008 When running this I get Parse error: syntax error, unexpected '{' in C:\wamp\www\mail01.php on line 19 The $cust=$_POST["email"]; comes from another html page (email). This variable is the one that I would like to loop within this code. Cheers. <?php $DOCUMENT_ROOT=$_SERVER['DOCUMENT_ROOT']; $cust=$_POST["email"]; $friend=$_POST["address"]; $output= "\t".$friend."\n"; echo "Your email is: ".$cust; @ $fp= fopen ("$DOCUMENT_ROOT/rcfriend.txt",'a+'); fwrite ($fp,$output, strlen($output)); fclose($fp); ?> <form action="http://localhost/mail01.php" method="post"> <table border="0" align="left"> <tr> <td>Friends Email: </td> <td align="left"><input type="text" name="address" size=40 maxlength=50></td> </tr> <td colspan=2 align=center><input type=submit value="Send Details"></td> </tr> Woops, didn't understand your file structure the first time. I fixed the code so it works, but now what exactly are you trying to do after this? Link to comment https://forums.phpfreaks.com/topic/102394-solved-writing-to-file/#findComment-524336 Share on other sites More sharing options...
spillage Posted April 22, 2008 Author Share Posted April 22, 2008 When they submit the information I want to have the $cust (your email is) email still showing on the page so if they then submit another friends email both emails are written to the file and not just the friends email. Hope this makes sense. Cheers. Link to comment https://forums.phpfreaks.com/topic/102394-solved-writing-to-file/#findComment-524343 Share on other sites More sharing options...
DarkWater Posted April 22, 2008 Share Posted April 22, 2008 When they submit the information I want to have the $cust (your email is) email still showing on the page so if they then submit another friends email both emails are written to the file and not just the friends email. Hope this makes sense. Cheers. Add this to the top: session_start(); if (isset($_POST['email'])) { $_SESSION['email']=$_POST['email']; } $cust = $_SESSION['email']; Put the instead of your current $cust lines, and add session_start() as the VERY first line under <?php. Link to comment https://forums.phpfreaks.com/topic/102394-solved-writing-to-file/#findComment-524347 Share on other sites More sharing options...
spillage Posted April 22, 2008 Author Share Posted April 22, 2008 Thanks ever so much. Works a treat. Must admit learning from a book by myself and have as yet not reached the session chapter. Have about another 300 pages to go untill that one. Cheers, Mark Link to comment https://forums.phpfreaks.com/topic/102394-solved-writing-to-file/#findComment-524352 Share on other sites More sharing options...
DarkWater Posted April 22, 2008 Share Posted April 22, 2008 Which book? If it's the one I'm thinking of, then you'll be fine once you get through it. Link to comment https://forums.phpfreaks.com/topic/102394-solved-writing-to-file/#findComment-524354 Share on other sites More sharing options...
spillage Posted April 22, 2008 Author Share Posted April 22, 2008 php and mysql web development third edition purple spine and pic of some arches on the front. quite hard going but having to learn html at the same time as never done anything like this before. Link to comment https://forums.phpfreaks.com/topic/102394-solved-writing-to-file/#findComment-524360 Share on other sites More sharing options...
DarkWater Posted April 22, 2008 Share Posted April 22, 2008 php and mysql web development third edition purple spine and pic of some arches on the front. quite hard going but having to learn html at the same time as never done anything like this before. Who's the author? Link to comment https://forums.phpfreaks.com/topic/102394-solved-writing-to-file/#findComment-524362 Share on other sites More sharing options...
spillage Posted April 22, 2008 Author Share Posted April 22, 2008 luke wellington and laura thomson Link to comment https://forums.phpfreaks.com/topic/102394-solved-writing-to-file/#findComment-524377 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.