Help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mrfruits
Forum Newbie
Posts: 5
Joined: Wed Feb 27, 2008 9:53 pm

Help

Post by mrfruits »

Hi I am brand new to PHP code. I was wondering if any of you could help. I am trying to get a multi line text box to show up using PHP. I then would like what ever is in the text box to be put into a text file after hitting a button. And I have no Idea how to do this. Any help would be awesome.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Help

Post by Christopher »

Show the code you have done so far.
(#10850)
mrfruits
Forum Newbie
Posts: 5
Joined: Wed Feb 27, 2008 9:53 pm

Re: Help

Post by mrfruits »

Code: Select all

<html>
<head>
<title>A BASIC HTML FORM</title>
 
<FORM NAME ="form1" METHOD ="POST" ACTION = "photocheck.php">
 
<input type="text" name="photo" />
<INPUT TYPE = "Submit" Name = "Submit1" VALUE = "Add">
 
</FORM>
 
 
<?PHP
$myFile = "photocheck.txt";
$fh = fopen($myFile, 'a') or die("can't open file");
$stringData = "\n";
fwrite($fh, $stringData);
$stringData = $_POST['photo'];
fwrite($fh, $stringData);
fclose($fh);
 
?>
 
 
</head>
it runs into a few problems. 1. it will always add a newline to the text file after it reloads. 2. if you add text, say the letter 'A' and submit, then reload 3 times then A will be in the text file 4 times.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Help

Post by Jonah Bron »

I think that's because it was submited once, plus three more times, coming to a total of four (if I understand correctly)

Code: Select all

<?php
if (isset($_POST['photo'])){
  fwrite(fopen('photocheck.txt', 'a'), (file_get_contents('photocheck.txt') ? "\n" : false) . $_POST['photo']);
}
?>
The above code checks if there have already been entries into photocheck.txt, and if there are, it makes a new line before the info, and if not, no new line.
mrfruits
Forum Newbie
Posts: 5
Joined: Wed Feb 27, 2008 9:53 pm

Re: Help

Post by mrfruits »

thanks, Is there a way to make it put a new line at the end of the info if there is info?

Also I was wondering if its possible to get the list of info from a text into a drop down list box and then select and item like http://www.website.com/image1.jpg and then have the image displayed? But then have an option to delete that image from the text file, and get ride of the white space line if there is one.
Post Reply