Total members 10262 | Gratitudes |It is currently Thu May 24, 2012 5:23 am Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 7 posts ] 
Author Question
 Question subject: How to make PHP form data saved into txt file
PostPosted: Sun Apr 10, 2011 4:51 pm 
Offline
Newbie
User avatar

Joined: Sun Apr 10, 2011 4:21 pm
Posts: 6
Has thanked: 0 time
Have thanks: 0 time

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.


TOP
 Profile Send private message  
Reply with quote  
 Question subject: Re: How to make PHP form data saved into txt file
PostPosted: Sun Apr 10, 2011 9:08 pm 
Offline
Mastermind
User avatar

Joined: Tue Mar 27, 2007 10:55 pm
Posts: 2279
Location: Earth
Has thanked: 39 time
Have thanks: 61 time
write to file using php

_________________
Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )


TOP
 Profile Send private message  
Reply with quote  
 Question subject: Re: How to make PHP form data saved into txt file
PostPosted: Mon Apr 11, 2011 5:21 am 
Offline
Newbie
User avatar

Joined: Sun Apr 10, 2011 4:21 pm
Posts: 6
Has thanked: 0 time
Have thanks: 0 time
I need something exactly like this


Attachments:
File comment: Every person added is shown in List of MA persons
Form.jpg
Form.jpg [ 93.18 KiB | Viewed 1362 times ]
TOP
 Profile Send private message  
Reply with quote  
 Question subject: Re: How to make PHP form data saved into txt file
PostPosted: Mon Apr 11, 2011 11:50 am 
Offline
Mastermind
User avatar

Joined: Tue Mar 27, 2007 10:55 pm
Posts: 2279
Location: Earth
Has thanked: 39 time
Have thanks: 61 time
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

_________________
Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )


TOP
 Profile Send private message  
Reply with quote  
 Question subject: Re: How to make PHP form data saved into txt file
PostPosted: Mon Apr 11, 2011 12:39 pm 
Offline
Newbie
User avatar

Joined: Sun Apr 10, 2011 4:21 pm
Posts: 6
Has thanked: 0 time
Have thanks: 0 time
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>



TOP
 Profile Send private message  
Reply with quote  
 Question subject: Re: How to make PHP form data saved into txt file
PostPosted: 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:


TOP
  
Reply with quote  
 Question subject: Re: How to make PHP form data saved into txt file
PostPosted: Tue Dec 20, 2011 3:32 pm 
Offline
Newbie
User avatar

Joined: Sun Dec 12, 2010 4:37 pm
Posts: 8
Has thanked: 0 time
Have thanks: 0 time
Amir! You have very nice photo on Facebook.


TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 7 posts ] 
Quick reply


  

 Similar topics
 Image Insert in Excel File Using POI
 ASP file structure
 Search records from text file
 Appriori witn uncertain data
 error closing file matlab save
 Data Encryption Standard (DES)
 How to download any file in jsp.
 data leakage detection coding in java
 read php file in asp and display it as html
 javascript read file

All times are UTC [ DST ]


Users browsing similar posts

Users browsing this forum: No registered users and 1 guest



Jump to:  
Previous Question | Next Question 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team