Page 1 of 1

Help

Posted: Wed Feb 27, 2008 9:56 pm
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.

Re: Help

Posted: Thu Feb 28, 2008 12:08 am
by Christopher
Show the code you have done so far.

Re: Help

Posted: Thu Feb 28, 2008 1:25 am
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.

Re: Help

Posted: Thu Feb 28, 2008 1:36 pm
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.

Re: Help

Posted: Thu Feb 28, 2008 7:07 pm
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.