[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.


Closed Thread
 
LinkBack Thread Tools
Old 08-09-2005, 08:16 PM   #1 (permalink)
NamePros Member
 
Infernal's Avatar
 
Join Date: May 2005
Location: Cheshire, England
Posts: 49
90.00 NP$ (Donate)

Infernal is an unknown quantity at this point


i am also in need of php help :(

imjust bstarting to learn php, and i would like some help on appending a file using a form.

e.g
i have index.php in my browser and it has a text field on it i want whatever is in the text field to write to the file test.txt

this is the current code i have (dont laugh plz, this is the second day ive tryed and learnt php (about the 3rd hour))

PHP Code:
<?php
$myfile
= "test.txt";
$f = fopen($myfile, 'a') or die("can't open file");
$ind = "index.php";

echo
"
<table border=0 cellspacing=0 cellpadding=1>
  <tr>
    <td>
<form action=\"$ind\" method=\"POST\">
    <p>Input:
          <input style=\"width:400\" type=\"text\" name=\"input\" value=\"$txt\" />
  </p>
    <p>
         <input name=\"submit\" type=\"submit\" value=\"submit\" />
    </p>
</form>
</td>
  </tr>
</table>"
;

?>
thanks for any help you might have

Inf
__________________
http://www.InfernalGFX.co.uk // Nearing Completion
Infernal is offline  
Old 08-09-2005, 08:28 PM   #2 (permalink)
Senior Member
 
luxinterior's Avatar
 
Join Date: Jul 2004
Location: Kizmiaz
Posts: 1,091
638.00 NP$ (Donate)

luxinterior is a glorious beacon of lightluxinterior is a glorious beacon of lightluxinterior is a glorious beacon of lightluxinterior is a glorious beacon of lightluxinterior is a glorious beacon of light


Take a look at the example in the manual: http://ph.php.net/manual/en/function.fopen.php

Also try not to mix your PHP and Html. It's better to get into good habits earlier rather than later

Lux

PS: you've got the variable $txt but you're never writing anything to it...
luxinterior is offline  
Old 08-10-2005, 06:54 AM   #3 (permalink)
NamePros Member
 
Infernal's Avatar
 
Join Date: May 2005
Location: Cheshire, England
Posts: 49
90.00 NP$ (Donate)

Infernal is an unknown quantity at this point


okay i know all of that on the link you gave me, its kinda not what i asked. can anyone else help me? theres a script called cutenews that uses this method. ive been looking at its php and i cant figure out how it works if nobody can help then nevermind thanks anyway

Inf
__________________
http://www.InfernalGFX.co.uk // Nearing Completion
Infernal is offline  
Old 08-10-2005, 07:41 AM   #4 (permalink)
DNOA Member
 
mholt's Avatar
 
Join Date: May 2004
Location: Utah
Posts: 5,041
18.01 NP$ (Donate)

mholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant future

Autism Marrow Donor Program 9/11/01 :: Never Forget Multiple Sclerosis Adoption Alzheimer's Lou Gehrig's Disease (ALS)
PHP Code:
<?php
$myfile
= "test.txt";
$f = fopen($myfile, 'a') or die("can't open file");

//Let's not mix your PHP... also - use single quotes, like this: echo('text'); - it parses faster.
//And, instead of making a variable called $ind, let's just write index.php ;)
?>
<table border=0 cellspacing=0 cellpadding=1>
  <tr>
    <td>
<form action="index.php" method="POST">
    <p>Input:
          <input size="50" type="text" name="input" value="<?php echo($txt) ?>" />
  </p>
    <p>
         <input name="submit" type="submit" value="submit" />
    </p>
</form>
</td>
  </tr>
</table>
I revised it a little bit - I don't have much time right now. I also fixed up that HTML form, style='width:400' won't work for a textbox. Instead, I used size="50".
__________________
codeboards

A high-quality community of programmers -- Join today and post! We want new members!
mholt is offline  
Old 08-10-2005, 08:14 AM   #5 (permalink)
Eating Pie
 
iNod's Avatar
 
Join Date: Nov 2004
Location: Canada
Posts: 2,289
126.05 NP$ (Donate)

iNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud of

Special Olympics AIDS/HIV Cystic Fibrosis Save The Children Baby Health Cystic Fibrosis
Next code you will need is the writing code. There are many different ways of doing this mind you. As well if this isn't private information txt file is fine if it is try finding another format such as .db or try adding none viewing into htaccess

Anyways the code for the fwrite you can learn at
http://www.php.net/fwrite
This fwrite function is the function which writes to an opened file.
Also make sure you chmod the file text.txt to 777.

Best of luck. Please post when you finsh your project!
__________________
I feel old.
iNod is offline  
Old 08-10-2005, 04:10 PM   #6 (permalink)
NPQ's PA, Slave, and On Call Coder

Technical Services


 
Eric's Avatar
 
Join Date: Mar 2005
Posts: 4,545
0.71 NP$ (Donate)

Eric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond repute

Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse
PHP Code:
<?php

/*Something like this MAY work :) */

$myfile = "test.txt";
$fp = fopen($myfile, 'w+') or die("can't open file");

?>
<table border=0 cellspacing=0 cellpadding=1>
  <tr>
    <td>
<form action="index.php" method="POST">
    <p>Input:
          <input size="50" type="text" name="input" value="<?php echo($txt) ?>" />
  </p>
    <p>
         <input name="submit" type="submit" value="submit" />
    </p>
</form>
</td>
  </tr>
</table>
<?php

fwrite
($fp, $txt);
fclose($fp);

?>
__________________
Eric is offline  
Old 08-10-2005, 05:49 PM   #7 (permalink)
Eating Pie
 
iNod's Avatar
 
Join Date: Nov 2004
Location: Canada
Posts: 2,289
126.05 NP$ (Donate)

iNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud of

Special Olympics AIDS/HIV Cystic Fibrosis Save The Children Baby Health Cystic Fibrosis
Quote:
Originally Posted by SecondVersion
PHP Code:
<?php

/*Something like this MAY work :) */

$myfile = "test.txt";
$fp = fopen($myfile, 'w+') or die("can't open file");

?>
<table border=0 cellspacing=0 cellpadding=1>
  <tr>
    <td>
<form action="index.php" method="POST">
    <p>Input:
          <input size="50" type="text" name="input" value="<?php echo($txt) ?>" />
  </p>
    <p>
         <input name="submit" type="submit" value="submit" />
    </p>
</form>
</td>
  </tr>
</table>
<?php

fwrite
($fp, $txt);
fclose($fp);

?>

That may work but you should verify that the fields are actually there.. Here is a fixed version of your code.
PHP Code:
<?php
/*Make sure to check that the fields where inputed.. You can produce an error if you wish but for now I will just leave it at this */

if(isset($_POST['input'], $_POST['submit'])) {
/*Something like this MAY work :) */

$myfile = "test.txt";
$fp = fopen($myfile, 'w+') or die("can't open file");

fwrite($fp, $txt);
fclose($fp);
}else{
?>
<table border=0 cellspacing=0 cellpadding=1>
  <tr>
    <td>
<form action="index.php" method="POST">
    <p>Input:
          <input size="50" type="text" name="input" value="<?php echo($txt) ?>" />
  </p>
    <p>
         <input name="submit" type="submit" value="submit" />
    </p>
</form>
</td>
  </tr>
</table>
<?php } ?>
This parses faster if you don't output the html within the php.

Wish you the best of luck.
__________________
I feel old.
iNod is offline  
Old 08-10-2005, 06:04 PM   #8 (permalink)
NamePros Member
 
Infernal's Avatar
 
Join Date: May 2005
Location: Cheshire, England
Posts: 49
90.00 NP$ (Donate)

Infernal is an unknown quantity at this point


okay if my SEMI WORKING database does not work i will try using all of the versions you guys have posted, but i just coded this and it partially works. feel free to try it out, it appends files quite well i guess, needs tweaking though, thanks for the help guys

PHP Code:
<?php
$myFile
= "test.txt";
$f=fopen("test.txt","a") or die("can't open file");
$txt=$_POST["text"];

$stringData = $_POST["text"];
fwrite($f, $stringData);

echo
"
<table border=0 cellspacing=0 cellpadding=1>
  <tr>
    <td>
<form action=\"form.php\" method=\"POST\">
    <p>Input:
          <input size=\"50\" type=\"text\" name=\"text\" />
  </p>
    <p>
         <input name=\"submit\" type=\"submit\" value=\"submit\" />
    </p>
</form>
</td>
  </tr>
</table>"
;

fclose($f);

echo
"You just wrote ";
echo
"$txt";
echo
" to the database!"

?>
Inf

EDIT:----->

okay i have done it, and it is currently under further development eventually ill have a full script for use with the templates i will be selling

a sample of the script is......
http://www.infernalgfx.co.uk/tests/p...ffdb2/form.php
just write something in the box and submit it, it then takes you to a screen confirming what you just wrote (this is the form that actually adds to the database). once you have wrote to that click this link:
http://www.infernalgfx.co.uk/tests/p...ffdb2/test.txt
and it shows what you just wrote (at the bottom and encoded in html(if you ctrl+a to select it all and paste it into dreamweaver or front page you will see it in a graphical view))

thanks

Inf
__________________
http://www.InfernalGFX.co.uk // Nearing Completion

Last edited by Infernal; 08-10-2005 at 07:05 PM.
Infernal is offline  
Old 08-10-2005, 07:11 PM   #9 (permalink)
Eating Pie
 
iNod's Avatar
 
Join Date: Nov 2004
Location: Canada
Posts: 2,289
126.05 NP$ (Donate)

iNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud of

Special Olympics AIDS/HIV Cystic Fibrosis Save The Children Baby Health Cystic Fibrosis
Nice Job!

Good luck with the full script if you need any help just post
__________________
I feel old.
iNod is offline  
Old 08-20-2005, 03:41 AM   #10 (permalink)
NamePros Regular
 
Zubair1's Avatar
 
Join Date: Mar 2005
Posts: 874
159.45 NP$ (Donate)

Zubair1 is just really niceZubair1 is just really niceZubair1 is just really niceZubair1 is just really nice

AIDS/HIV
try using the the mode a+ when you assigning the file handler.
__________________
Live Support : Zubair11 [at] hotmail.com
Free SEO Directory! || Free Games and Songs || eBloggy.net
Zubair.info || Mixcat Interactive
Zubair1 is offline  
Closed Thread


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

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Tutorial: Getting started with PHP (The Basics) deadserious Webmaster Tutorials 60 11-17-2007 11:35 AM
Googlism - What does google think of you? deadserious The Break Room 55 12-15-2005 09:09 AM
Beware of PHP! PolurNET The Break Room 25 03-29-2005 03:04 PM

Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 05:15 AM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85