NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page i am also in need of php help :(

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

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 08-09-2005, 09:16 PM THREAD STARTER               #1 (permalink)
NamePros Member
 
Infernal's Avatar
Join Date: May 2005
Location: Cheshire, England
Posts: 49
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
????: NamePros.com http://www.namepros.com/programming/114240-i-am-also-need-php-help.html
$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, 09:28 PM   #2 (permalink)
Senior Member
 
luxinterior's Avatar
Join Date: Jul 2004
Location: Kizmiaz
Posts: 1,091
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 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, 07:54 AM THREAD STARTER               #3 (permalink)
NamePros Member
 
Infernal's Avatar
Join Date: May 2005
Location: Cheshire, England
Posts: 49
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, 08:41 AM   #4 (permalink)
DNOA Member
Join Date: May 2004
Posts: 5,040
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?>" />
????: NamePros.com http://www.namepros.com/showthread.php?t=114240
  </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".
mholt is offline  
Old 08-10-2005, 09:14 AM   #5 (permalink)
Eating Pie
 
iNod's Avatar
Join Date: Nov 2004
Location: Canada
Posts: 2,272
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, 05:10 PM   #6 (permalink)
Senior Member
 
Eric's Avatar
Join Date: Mar 2005
Posts: 4,948
Eric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatness
 

Member of the Month
MOTM September 2005
Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Animal Rescue Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Baby Health Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse Diabetes Protect Our Planet Multiple Sclerosis Autism Adoption Special Olympics
PHP Code:
<?php

/*Something like this MAY work :) */

$myfile "test.txt";
$fp fopen($myfile'w+') or die("can't open file");
????: NamePros.com http://www.namepros.com/showthread.php?t=114240

?>
<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, 06:49 PM   #7 (permalink)
Eating Pie
 
iNod's Avatar
Join Date: Nov 2004
Location: Canada
Posts: 2,272
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
Originally Posted by SecondVersion
PHP Code:
<?php
????: NamePros.com http://www.namepros.com/showthread.php?t=114240

/*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 */
????: NamePros.com http://www.namepros.com/showthread.php?t=114240

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, 07:04 PM THREAD STARTER               #8 (permalink)
NamePros Member
 
Infernal's Avatar
Join Date: May 2005
Location: Cheshire, England
Posts: 49
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>
????: NamePros.com http://www.namepros.com/showthread.php?t=114240
    <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))
????: NamePros.com http://www.namepros.com/showthread.php?t=114240

thanks

Inf
__________________
http://www.InfernalGFX.co.uk // Nearing Completion
Last edited by Infernal; 08-10-2005 at 08:05 PM.
Infernal is offline  
Old 08-10-2005, 08:11 PM   #9 (permalink)
Eating Pie
 
iNod's Avatar
Join Date: Nov 2004
Location: Canada
Posts: 2,272
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, 04:41 AM   #10 (permalink)
NamePros Regular
 
Zubair1's Avatar
Join Date: Mar 2005
Posts: 912
Zubair1 is just really niceZubair1 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 Online TV || Tech Blog
Web Design & Web Development Services || Reliable Web Hosting
Zubair1 is offline  
Closed Thread


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


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

Liquid Web Smart Servers  
All times are GMT -7. The time now is 09:35 PM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger