Help
Moderator: General Moderators
Help
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.
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Help
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>- Jonah Bron
- DevNet Master
- Posts: 2764
- Joined: Thu Mar 15, 2007 6:28 pm
- Location: Redding, California
Re: Help
I think that's because it was submited once, plus three more times, coming to a total of four (if I understand correctly)
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.
Code: Select all
<?php
if (isset($_POST['photo'])){
fwrite(fopen('photocheck.txt', 'a'), (file_get_contents('photocheck.txt') ? "\n" : false) . $_POST['photo']);
}
?>Re: Help
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.
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.