Page 1 of 1

Help needed with fwrite

Posted: Mon Jun 15, 2009 11:58 pm
by cool30
I have an form in which when the user types first name, that data should be written in a .txt file. Below is the code with which the a .txt file is created. When $string_data is passed ,it passes the data "How are you" to textFile.txt but how can I pass the contents of a text field name "FirstName" to "textFile.txt". I appreciate any help.

Code: Select all

 
if(isset($_POST['Submit']))
 { 
  touch("textFile.txt");
  $FirstName = $_POST['FirstName'];(this doesn't seems to be working)
    $myfile = "textFile.txt";
    $fh = fopen($myfile,'w') or die("Can't open the file"):;
    
    //$string_data = "How are you";
    
    fwrite ($fh, $FirstName);
    fclose($fh);
 
 
 
 

Re: Help needed with fwrite

Posted: Tue Jun 16, 2009 12:14 am
by requinix
What's the form look like?

Re: Help needed with fwrite

Posted: Tue Jun 16, 2009 1:07 am
by cool30
form is below

Code: Select all

 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
 
<body>
<form id="form1" name="form1" method="POST" action="">
 
<label>First Name:
<input name="FirstName" type="text" value="First Name" />
</label>
 
  <?PHP   
  if(isset($_POST['Submit']))
 { 
  touch("textFile.txt");
  $string_data = $_POST['FirstName'];
    $myfile = "textFile.txt";
    $fh = fopen($myfile,'w') or die("Can't open the file"):;
    
    //$string_data = "How are you";
    
    fwrite ($fh, $string_data);
    fclose($fh);
    }
 
  ?>
 
<p>&nbsp;  </p>
<p>
  <input name="Submit" type="button" value="Submit" />
  
</p>
</form>
</body>
</html>