Switch to full style
Dynamic open source server-side web development
Post a reply

How to make PHP form data saved into txt file

Sun Apr 10, 2011 4:51 pm

Hello!
How can I make a PHP form data to be saved in a txt file.
I need to enter multiple records that should be inserted in the same text file.
For example: I have 5 persons. For each person I have Name, Date, Phone, Observations. The form must save all this persons data and put them in a txt file in the impun order.
I not sure if I made myself clear.



Re: How to make PHP form data saved into txt file

Sun Apr 10, 2011 9:08 pm

write to file using php

Re: How to make PHP form data saved into txt file

Mon Apr 11, 2011 5:21 am

I need something exactly like this
Attachments
Form.jpg
Every person added is shown in List of MA persons
Form.jpg (93.18 KiB) Viewed 14797 times

Re: How to make PHP form data saved into txt file

Mon Apr 11, 2011 11:50 am

hi friend , you want someone to write for you as freelancer ? anyway . this part of code will show your a big example :
PHP User Registration

Re: How to make PHP form data saved into txt file

Mon Apr 11, 2011 12:39 pm

I have the design but is not that simple.
I need to add multiple persons in one txt file
Code:

<!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=utf-8" />
<title>Untitled Document</title>
</head>
<html>
  <head>
  <title>Index</title>
  </head>
  <body>
  <h2 align="center">MA Persons</h2>
  <form name="forml" method="post" action="UserRegistrationFormOutput.php" enctype="multipart/form-data">
    <table width="50%" border="0" align="center" cellpadding="5" cellspacing="0">
      <tr>
        <td width="9%">Name:</td>
        <td width="91%"><input type="text" name="name" size="100" maxlength="100">
         </div>
        </td>
      </tr>
      <tr>
        <td width="9%"> Date of Birth:</td>
        <td height="2"><input type="text" name="name2" size="100" maxlength="100" /></td>
      </tr>
      <tr>
        <td width="9%" height="32">V Type:</td>
        <td height="32"><input type="text" name="name3" size="100" maxlength="100" /></td>
      </tr>
      <tr>
        <td width="9%">Begining with:</td>
        <td height="2"><input type="text" name="name4" size="100" maxlength="100" /></td>
      </tr>
      <tr>
        <td width="9%">Observations:</td>
        <td height="2"><textarea name="address" cols="97" rows="4">  </textarea></td>
      </tr>
      <tr>
        <td width="9%" height="5">Rejected:</td>
        <td height="5"><textarea name="address2" cols="97" rows="4">  </textarea></td>
      </tr>
      <tr>
        <td width="9%">Why</td>
        <td height="2"><textarea name="address3" cols="97" rows="4">  </textarea></td>
      </tr>

      <tr>
        <td colspan="2">
          <div align="center">
            <input type="submit" name="Submit" value="Add person" />
            <input type="submit" name="Submit2" value="Modify person" />
            <input type="submit" name="Submit3" value="Delete person" />
            <input type="submit" name="Submit4" value="Save file" />
            <input type="submit" name="Submit5" value="Exit application" />
          </div>
        </td>
      </tr>
    </table>
  </form>
  </body>
  </html>

<body>
</body>
</html>



Re: How to make PHP form data saved into txt file

Sun Jul 17, 2011 6:26 pm

Radu wrote:I have the design but is not that simple.
I need to add multiple persons in one txt file
Code:

<!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=utf-8" />
<title>Untitled Document</title>
</head>
<html>
  <head>
  <title>Index</title>
  </head>
  <body>
  <h2 align="center">MA Persons</h2>
  <form name="forml" method="post" action="UserRegistrationFormOutput.php" enctype="multipart/form-data">
    <table width="50%" border="0" align="center" cellpadding="5" cellspacing="0">
      <tr>
        <td width="9%">Name:</td>
        <td width="91%"><input type="text" name="name" size="100" maxlength="100">
         </div>
        </td>
      </tr>
      <tr>
        <td width="9%"> Date of Birth:</td>
        <td height="2"><input type="text" name="name2" size="100" maxlength="100" /></td>
      </tr>
      <tr>
        <td width="9%" height="32">V Type:</td>
        <td height="32"><input type="text" name="name3" size="100" maxlength="100" /></td>
      </tr>
      <tr>
        <td width="9%">Begining with:</td>
        <td height="2"><input type="text" name="name4" size="100" maxlength="100" /></td>
      </tr>
      <tr>
        <td width="9%">Observations:</td>
        <td height="2"><textarea name="address" cols="97" rows="4">  </textarea></td>
      </tr>
      <tr>
        <td width="9%" height="5">Rejected:</td>
        <td height="5"><textarea name="address2" cols="97" rows="4">  </textarea></td>
      </tr>
      <tr>
        <td width="9%">Why</td>
        <td height="2"><textarea name="address3" cols="97" rows="4">  </textarea></td>
      </tr>

      <tr>
        <td colspan="2">
          <div align="center">
            <input type="submit" name="Submit" value="Add person" />
            <input type="submit" name="Submit2" value="Modify person" />
            <input type="submit" name="Submit3" value="Delete person" />
            <input type="submit" name="Submit4" value="Save file" />
            <input type="submit" name="Submit5" value="Exit application" />
          </div>
        </td>
      </tr>
    </table>
  </form>
  </body>
  </html>

<body>
</body>
</html>


index.php
Code:
<?php
$name = empty($_GET["name"]) ? "" : $_GET["name"];
$dateofbirth = empty($_GET["dateofbirth"]) ? "" : $_GET["dateofbirth"];
$vtype = empty($_GET["vtype"]) ? "" : $_GET["vtype"];
$beginingwith = empty($_GET["beginingwith"]) ? "" : $_GET["beginingwith"];
$observations = empty($_GET["observations"]) ? "" : $_GET["observations"];
$rejected = empty($_GET["rejected"]) ? "" : $_GET["rejected"];
$why = empty($_GET["why"]) ? "" : $_GET["why"];
if(!$name){$message1 = "Name.";}
if(!$dateofbirth){$message2 = "Date of Birth.";}
if(!$vtype){$message3 = "V Type.";}
if(!$beginingwith){$message4 = "Begining with.";}
if(!$observations){$message7 = "Observations.";}
if(!$rejected){$message5 = "Rejected.";}
if(!$why){$message6 = "Why.";}
?>
<html>
  <head>
  <title>Index</title>
  </head>
  <body>
  <h2 align="center">MA Persons</h2>
  <form method="post" action="store_it.php">
    <table width="50%" border="0" align="center" cellpadding="5" cellspacing="0">
      <tr>
        <td width="9%"><?php echo $message1; ?></td>
        <td width="91%"><input type="text" name="name" size="100" maxlength="100" value="<?php echo $name; ?>">
         </div>
        </td>
      </tr>
      <tr>
        <td width="9%"><?php echo $message2; ?></td>
        <td height="2"><input type="text" name="dob" size="100" maxlength="100" value="<?php echo $dateofbirth; ?>"></td>
      </tr>
      <tr>
        <td width="9%" height="32"><?php echo $message3; ?></td>
        <td height="32"><input type="text" name="vtype" size="100" maxlength="100" value="<?php echo $vtype; ?>"></td>
      </tr>
      <tr>
        <td width="9%"><?php echo $message4; ?></td>
        <td height="2"><input type="text" name="bw" size="100" maxlength="100" value="<?php echo $beginingwith; ?>"></td>
      </tr>
      <tr>
        <td width="9%"><?php echo $message7; ?></td>
        <td height="2"><textarea name="ob" cols="97" rows="4" value="<?php echo $observations; ?>">  </textarea></td>
      </tr>
      <tr>
        <td width="9%" height="5"><?php echo $message5; ?></td>
        <td height="5"><textarea name="rej" cols="97" rows="4" value="<?php echo $rejected; ?>">  </textarea></td>
      </tr>
      <tr>
        <td width="9%"><?php echo $message6; ?></td>
        <td height="2"><textarea name="why" cols="97" rows="4" value="<?php echo $why; ?>">  </textarea></td>
      </tr>

      <tr>
        <td colspan="2">
          <div align="center">
            <input type="submit" name="Submit" value="Add person" />

          </div>
        </td>
      </tr>
    </table>
  </form>
  </body>
  </html>

<body>
</body>
</html>

store_it.php
Code:
<?php
$name = empty($_POST["name"]) ? "" : $_POST["name"];
$dob = empty($_POST["dob"]) ? "" : $_POST["dob"];
$bw = empty($_POST["bw"]) ? "" : $_POST["bw"];
$vtype = empty($_POST["vtype"]) ? "" : $_POST["vtype"];
$ob = empty($_POST["ob"]) ? "" : $_POST["ob"];
$rej = empty($_POST["rej"]) ? "" : $_POST["rej"];
$why = empty($_POST["why"]) ? "" : $_POST["why"];
if(!$name || !$dob || !$bw || !$vtype || !$ob || !$rej || !$why){header("location:index.php?name=$name&dateofbirth=$dob&beginingwith=$bw&vtype=$vtype&observations=$ob&rejected=$rej&why=$why");}
else
{
$file = "PhoneBook.txt";
$a = fopen($file, "a");
fwrite($a,$name."\r\n");
fwrite($a,$dob."\r\n");
fwrite($a,$vtype."\r\n");
fwrite($a,$bw."\r\n");
fwrite($a,$ob."\r\n");
fwrite($a,$rej."\r\n");
fwrite($a,$why."\r\n");
fclose($a);
  $a = fopen($file, "r");
echo "<table border='1'>";
echo "<tr><th>Name</th><th>Date Of Birth</th><th>V-Type</th><th>Begining With</th><th>Observations</th><th>Rejected</th><th>Why</th></tr>";
while(!feof($a))
{
  echo "<tr><td>".fgets($a)."</td><td>".fgets($a)."</td><td>".fgets($a)."</td><td>".fgets($a)."</td><td>".fgets($a)."</td><td>".fgets($a)."</td><td>".fgets($a)."</td></tr>";
  }
echo "</table>";
fclose($a);
}
?>
Save Successfully!<br>
Want to add Another Entry? Click Add Another Button
<form action="index.php">
<input type="submit" value="Add another">
</form>


this is what you can expect from a 9th grade student??? :mrgreen:
my facebook is http://facebook.com/incredibleamir feel free to send me friend request :blush:

Re: How to make PHP form data saved into txt file

Tue Dec 20, 2011 3:32 pm

Amir! You have very nice photo on Facebook.

Post a reply
  Related Posts  to : How to make PHP form data saved into txt file
 the text file i saved all in one line. How can i solve it?     -  
 Send data without a form     -  
 form to insert data, upload many files and images , database     -  
 calling method to form- displaying textbox data in messagbox     -  
 Earn $2 Per Form Filled. Now Hiring Data Entry Typists     -  
 make jar file for mobile     -  
 How to make Secure Jar file     -  
 PHP HTML form with to file upload     -  
 How to merge the data into file     -  
 Loading table data from a CSV file     -