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 Quote Link to comment 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? Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment Share on other sites More sharing options...
spillage Posted April 22, 2008 Author Share Posted April 22, 2008 luke wellington and laura thomson Quote Link to comment 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.