Jump to content

[SOLVED] writing to file


spillage

Recommended Posts

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
Share on other sites

<?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
Share on other sites

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
Share on other sites

<?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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.