PHP form ....

Da_iMac_Daddy

Not-so-Neo-DumbA$$
Can someone give me and example of how I would create a page that would first ask for a password and user name then send me to a page where I would be able to fill in a text box then have that saved into another text file and automatically add the date to the top. Then I need to plop that sucker into another html Page and format it.

OK well you probably won't give me and example or write it for me but could someone lead me to some info that would help me to do it myself?
 
OK let me bust this up a little ... I have figured out how to write to a text file. now what I want to do is be able to have the text I write from the file come from a field which I can fill out in my browser and hit a button like submit or something and have it send it to the variable $string

Code:
<?php
$filename ="abc.txt";
$handle= fopen($filename,'a');
$string="Hello World";
fputs($handle, $string);
fclose($handle);
?>

:edit:

just uploaded the page I would like to use to deal with the php code it's here
now how do I go about linking it to php to edit a text file?
 
Just make a regular form with dreamweaver or whatever you like. Then the comments field would be called 'comments'

then have it go to input.php when they hit submit. that page would have this code

Code:
<?php
$filename ="abc.txt";
$handle= fopen($filename,'a');
$string=$comments;
fputs($handle, $string);
fclose($handle);
header("Location:[url]http://yoursite.com/apage.htm[/url]");
exit();
?>

You might need another piece of code. $_POST but i can't figure out how that goes right now. something like

$string=$POST_['comments'];

Hope i didn't just confuse you.

Twister

PHP.net for all kinds of PHP stuff
 
I thought it was $string = $_POST['comments'];

OK now I've got that all set up but when it tries to edit the file I get some errors

Code:
Warning: fopen("news.txt", "a") - Permission denied in /home/dekster/www/www/process.php on line 6

Warning: fputs(): supplied argument is not a valid File-Handle resource in /home/dekster/www/www/process.php on line 6

Warning: fclose(): supplied argument is not a valid File-Handle resource in /home/dekster/www/www/process.php on line 6
 
This is the code for the process.php
I tried changing the permissions on news.txt and that doesn't seem to change anything
news.txt is in /www ... ooops changed the code and now it just shows a blank page when I hit submit .. gotta go check and see if it worked :\

Code:
<?php
$filename = 'news.txt';
$comment = $_POST['textarea'];
$handle = fopen("ftp://nathacof:*******@ftp.dekster.com/www/news.txt", 'r+');
fputs($handle, $comment);
fclose($handle);
exit();
?>
 
hmm it didn't write anything to news.txt ... weird ... :\ ACK! I'm excited I think I'm actually getting close to getting this :D
 
get info on the text file. you have to make sure there are read and write privledges on it.

Twister
 
sorry i didn't read your code

this: $handle = fopen("ftp://nathacof:*******@ftp.dekster.com/www/news.txt", 'r+');

should be: $handle = fopen("http://yourwebsite.com/news.txt", 'r+');

Try that
 
this is what mine looks like. See if you can get it to work for you.

Code:
<?
    global $linkAddress, $category, $new_category, $linkDescription;

 $flat_file  =  "TMCLinks.txt";
 $links_url  =  "http://127.0.0.1/~twister/index.php";
 $dups_url  =  "http://127.0.0.1/~twister/index2.php";


        $links_file =  fopen ( $flat_file, "a+" );
     if ( $linkDescription ) {
      $new_link =  $category . "\t" . $linkAddress . "\t" . $linkDescription . "\n";
     }
     else {
      $new_link =  $category . "\t" . $linkAddress . "\n";
     }
        fwrite( $links_file, $new_link );
        fclose( $links_file );    }

 header( "Location: $links_url" );
?>
 
changing it to fopen("http://dekster.com/news.txt ", "r+"); didn't work ...

I have no idea whats going on ... the page is www.dekster.com/test.html, I dunno I use ftp to deal with all my site stuff so I figured I would use ftp to change stuff. This is tough.
 
The file news.txt hasn't changed

also before I had the PHP file embedded into html Now I've taken it out ... does it matter either way?
 
OK now I have it so that what is entered will be written to news.txt but it also writes over anything in it's way. I used the r+ flag to start at the beginning of the file but that's no use to me if it just writes over everything anyway. Any help here?
 
I tried to add
Code:
header("Location: [url]http://www.dekster.com/[/url]");
exit;

to my process.php script but it gives me this error

Code:
Warning: Cannot add header information -
 headers already sent by (output started at 
/home/dekster/www/www/process.php:10) in 
/home/dekster/www/www/process.php on line 11
 
Back
Top