Jump to content

Recommended Posts

Hi, i am having trouble saving the data entered in my HTML form into .txt format.

 

Here is my crappy HTML form

 

<div id="apDiv3"><h2 class="style3">About you</h2>
  <p>
<form action="write.php" method="get">
<table>
<tr><td><span class="style3">What is you name:</span></td><td><input name="Name" type="text" /></td></tr>
<tr><td height="26"><span class="style3">favourite Color:</span></td><td align="right">
  Blue :
    <input type="radio" value="Blue" name="col">
    :<br />
    Red :
    <input type="radio" value="Red" name="col">
    :<br />
    Green:
    <input type="radio" value="Green" name="col">
    :<br />
  </td>
<tr><td><span class="style3">Phone No.:</span></td><td><input name="phone" type="text" /></td></tr>
<tr><td colspan="2" align="center"><input name="Start" type="Submit" id="Start" value="Start" /></td></tr>
</table>
</form>
</div>

 

what i need is a php file to save the data entered in the form to a .txt file. if had a go at one here, but like the HTML form i think its not very good..

 

<?php
$Name = $_POST['Name'];
$Name = $_POST['col'];
$Name = $_POST['phone'];
$fp = fopen("output.txt","a+") or exit("unable to open the file");
if($fp != null)
{
fwrite($fp,$Name);
fwrite($fp,$col);
fwrite($fp,$phone);
}
fclose($fp);

?> 

 

i could do with some help..

Link to comment
https://forums.phpfreaks.com/topic/182931-help-with-saving-form-data/
Share on other sites

The strings you used to get the information from the form may be the problem!

<?php

$Name = $_POST['Name'];

$Name = $_POST['col'];

$Name = $_POST['phone'];

$fp = fopen("output.txt","a+") or exit("unable to open the file");

if($fp != null)

{

fwrite($fp,$Name);

fwrite($fp,$col);

fwrite($fp,$phone);

}

fclose($fp);

 

Try this:

 

<?php

// Get Information From Form

$Name = $_POST['Name'];

$Col = $_POST['col'];

$Phone = $_POST['phone'];

$myfile = "output.txt"

$fh = fopen($myfile,'a+');

  if(!$fh) {

  die("couldn't open file <i>$myfile</i>");

  }

  else {

  $str.= " $Name\r\n"; 

  $str.= " $Col\r\n";

  $str.= " $Phone\r\n";

  fwrite($fh, $str);

  }

  fclose($fh);

}

 

GOOD LUCK!

  • 2 weeks later...
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.