Current location: Hot Scripts Forums » General Community » Script Requests » Simple php script. Write fields to text file...append each time.


Simple php script. Write fields to text file...append each time.

Reply
  #1 (permalink)  
Old 01-19-07, 03:23 PM
WillR WillR is offline
New Member
 
Join Date: Jan 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
NEED HELP: Simple php script. Write fields to text file...append each time.

I'm trying to create a simple form... will have a bunch more fields but I can add those later.....

I want the form to write all fields... hit submit and it writes to a text file... then the next time someone goes to the form and does it..... it appends to the bottom of the document and seperates with a ---------------------

Can someone please help me finish. I don't know how to tie the submit button with the writing action. And I might be missing some other things. Like I'm not sure of proper format for fopen and fclose.

It's so long ago I learned it. I have spent some time serching and will continue to... jsut that I need this quick so if someone could help me out it would be much appreciated.

This is what I have so far:



PHP Code:

<table width="200" border="0" align="center">

  <tr>
    <td width="82">Name</td>
    <td width="108"><form name="form1" method="post" action="">
      <label>
      <input type="text" name="name">
        </label>
    </form>    </td>
  </tr>
  <tr>
    <td>Email</td>
    <td><form name="form2" method="post" action="">
      <input type="text" name="email">
    </form></td>
  </tr>
  <tr>
    <td>test</td>
    <td><input type="text" name="test"></td>
  </tr>
</table>

</p>
<p align="center">
  <input type="submit" name="Submit" value="Submit">
</p>



<p>
  <?php
 
$name 
$_POST["name"]; 
$email $_POST["email"]; 
$test $_POST["test"]; 
 
$file "$info.txt";

Last edited by Christian; 01-23-07 at 03:28 PM.
Reply With Quote
  #2 (permalink)  
Old 01-19-07, 06:30 PM
WillR WillR is offline
New Member
 
Join Date: Jan 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Well

This thread helped me.

http://www.programmingtalk.com/showt...047#post112047

And it works great.

Just would be nice if there was a way to do in ONE file.


My Code.



Code:
 

</style><form name="form1" method="post" action="test3.php">
  <table width="780" border="0" align="center">
    <tr>
      <td width="256"><span class="style5">Company Name:</span></td>
      <td width="514"><input name="company" type="text" id="company"></td>
    </tr>

    <tr>
      <td><span class="style5">Address
:</span></td>
      <td><input name="address1" type="text" id="address1" value=""></td>
    </tr>
    <tr>
      <td><span class="style5">Unit / Apt :</span></td>
      <td><input name="address2" type="text" id="address2"></td>
    </tr>
    <tr>
      <td><span class="style5">City, Pr : </span></td>
      <td><input name="address3" type="text" id="address3"></td>
    </tr>
    <tr>
      <td><span class="style5">Postal Code :</span></td>
      <td><input name="address4" type="text" id="address4"></td>
    </tr>
    <tr>
      <td><span class="style5">Contact Name: </span></td>
      <td><input name="contact" type="text" id="contact" value="First Name Last Name"></td>
    </tr>
    <tr>
      <td><span class="style5">Email: </span></td>
      <td><input name="contact2" type="text" id="contact2"></td>
    </tr>
    <tr>
      <td><span class="style5">Phone :</span></td>
      <td><input name="phone" type="text" id="phone" value="(   ) ">
      <input name="Submit" type="submit" class="style5" value="Submit"></td>
    </tr>
    <tr>
      <td colspan="2"><div align="center"></div></td>
    </tr>
  </table>
  <p align="center">&nbsp;</p>
  </form>


PHP page

PHP Code:



<?php

$company 
$_POST['company'];
$address1 $_POST['address1'];
$address2 $_POST['address2'];
$address3 $_POST['address3'];
$address4 $_POST['address4'];
$contact $_POST['contact'];
$contact2 $_POST['contact2'];
$phone $_POST['phone'];

//the data
$data "$company | $address1 | $address2 | $address3 | $address4 | $contact | $contact2 | $phone\n
"
;

//open the file and choose the mode
$fh fopen("customers.txt""a");
fwrite($fh$data);

//close the file
fclose($fh);

print 
"Information Submitted. Thanks";

?>

Last edited by Christian; 01-23-07 at 03:29 PM.
Reply With Quote
  #3 (permalink)  
Old 01-19-07, 08:35 PM
grafman grafman is offline
Coding Addict
 
Join Date: Dec 2006
Posts: 278
Thanks: 0
Thanked 0 Times in 0 Posts
Here you go, one file:

PHP Code:



<?php

if($_POST['Submit'])
{
$company $_POST['company'];
$address1 $_POST['address1'];
$address2 $_POST['address2'];
$address3 $_POST['address3'];
$address4 $_POST['address4'];
$contact $_POST['contact'];
$contact2 $_POST['contact2'];
$phone $_POST['phone'];

//the data
$data "$company | $address1 | $address2 | $address3 | $address4 | $contact | $contact2 | $phone\n
"
;

//open the file and choose the mode
$fh fopen("customers.txt""a");
fwrite($fh$data);

//close the file
fclose($fh);

print 
"Information Submitted. Thanks";
}
else
{
print <<<ENDOFTXT
</style><form name="form1" method="post" action="test3.php">
<table width="780" border="0" align="center">
<tr>
<td width="256"><span class="style5">Company Name:</span></td>
<td width="514"><input name="company" type="text" id="company"></td>
</tr>

<tr>
<td><span class="style5">Address
:</span></td>
<td><input name="address1" type="text" id="address1" value=""></td>
</tr>
<tr>
<td><span class="style5">Unit / Apt :</span></td>
<td><input name="address2" type="text" id="address2"></td>
</tr>
<tr>
<td><span class="style5">City, Pr : </span></td>
<td><input name="address3" type="text" id="address3"></td>
</tr>
<tr>
<td><span class="style5">Postal Code :</span></td>
<td><input name="address4" type="text" id="address4"></td>
</tr>
<tr>
<td><span class="style5">Contact Name: </span></td>
<td><input name="contact" type="text" id="contact" value="First Name Last Name"></td>
</tr>
<tr>
<td><span class="style5">Email: </span></td>
<td><input name="contact2" type="text" id="contact2"></td>
</tr>
<tr>
<td><span class="style5">Phone :</span></td>
<td><input name="phone" type="text" id="phone" value="( ) ">
<input name="Submit" type="submit" class="style5" value="Submit"></td>
</tr>
<tr>
<td colspan="2"><div align="center"></div></td>
</tr>
</table>
<p align="center">&nbsp;</p>
</form>
ENDOFTXT;
}

?>
__________________
"Things are difficult only while you don't understand them."
Reply With Quote
  #4 (permalink)  
Old 01-22-07, 02:53 PM
WillR WillR is offline
New Member
 
Join Date: Jan 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
oh.... easy enough.

Thank you so much.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP code to edit a text file mdhall Script Requests 12 12-23-10 04:03 AM
2 profitable script sites for sale cms-master.com General Advertisements 3 07-03-07 10:17 AM
PHP to extract info from a delimited text file 9999 PHP 8 07-17-06 03:08 AM
PHP Redirect Script based on User Text Field skipcollege Script Requests 7 09-18-05 11:03 AM
Request: text form and image uploading script (PHP) YHIEddie Script Requests 0 03-18-05 05:22 PM


All times are GMT -5. The time now is 11:32 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.