Adventure Game Studio

Community => General Discussion => Topic started by: LordHart on Wed 12/05/2004 03:32:17

Title: Anybody know PHP? (woohoo, working now! thanks guys!)
Post by: LordHart on Wed 12/05/2004 03:32:17
I'm trying to setup a PHP form on my site, which will just be a simple feedback form that sends the data the person submitted to a text file. I had originally had it in ASP, but I have found that my web server doesn't have a ASP client installed, so, no ASP.

I've only started learning PHP, so I don't really know how I could do it and things I've searched on google haven't really been helpful. Can anyone help me with this, as I don't really wanna register with a PHP site and post there (i'm too lazy)...

So far, all I've got is:

<?php   $filename = "feedback.txt" ;?>


So you can see, I have hardly any idea as what else to do. I figured you'd need a way to open the file to write to it, and I found fopen( ) ; would do that, but how would I write to the text file without removing anything that was previously there?
Title: Re: Anybody know PHP?
Post by: on Wed 12/05/2004 09:09:01
Quote from: Os àšltimo Quão Queijo ^_^ on Wed 12/05/2004 03:32:17So far, all I've got is:

<?phpÃ,  Ã, $filename = "feedback.txt" ;?>



<?php   $filename = "feedback.txt";   # WRITE #   $f = fopen($filename,"w");   fwrite($f,"w00t");   fclose($f);   # READ #   $f = fopen($filename,"r");   fread($f,filesize($filename)); # reads the whole file   fclose($f);?>

Title: Re: Anybody know PHP?
Post by: on Wed 12/05/2004 09:12:10
Whoops:
$data = fread($f,filesize($filename)); # reads the whole file


You can add $newstuff like this:
fwrite($f,$data.$newstuff); # '.' joins strings together

or
$f = fopen($filename,"a");
fwrite($f,$newstuff);
Title: Re: Anybody know PHP?
Post by: Ishmael on Wed 12/05/2004 09:50:38
... and that "are" in there is a small R...
Title: Re: Anybody know PHP?
Post by: AJA on Wed 12/05/2004 13:16:12
are...  ;D
I wonder where that came from :P
Title: Re: Anybody know PHP?
Post by: LordHart on Wed 12/05/2004 23:20:44
So, where it says w00t... thats what goes into the file? So to have multiple lines and taking the info from the three fields which are Name, Email and Comment... would I do:

<?php   $filename = "feedback.txt";   # WRITE #   $f = fopen($filename,"w");   fwrite($f,"$Name");   fwrite($f,"$Email");   fwrite($f,"");   fwrite($f,"$Comment");   fwrite($f,"========================");   fwrite($f,"");   fclose($f);   # READ #   $f = fopen($filename,"are");   fread($f,filesize($filename)); # reads the whole file   fclose($f);?>


So would that work?

edit: I found out why the r turns into are... auto txt remover thingy...
Title: Re: Anybody know PHP?
Post by: Fuzzpilz on Wed 12/05/2004 23:30:17
No, what you want is: (not colour coded because I'm lazy and it really serves no purpose anyway if you don't already understand what's going on)


<?
import_request_variables('gP','r_'); // imports request variables - you may or may not have to do this
$f=fopen('feedback.txt','a'); // opens feedback.txt for appending
fwrite($f,"$r_name\n$r_email\n\n$r_content\n=======================\n"); // adds stuff to the file, assuming the fields are called "name", "email" and "content"
fclose($f);
?>
Title: Re: Anybody know PHP?
Post by: LordHart on Thu 13/05/2004 00:34:09
It still doesn't work...

Heres my everything in my HTML file that deals with the form... maybe something wrong there... but I doubt it.

This is feedback.html...


<form action="feedback.php" method="post">

<input type="textarea" name="name" />
<input type="textarea" name="email" />
<textarea rows="5" cols="25" name="comments"></textarea>

<input type="submit" value="Submit Comment" />
<input type="reset" />

</form>


And then here is the php in the feedback.php:


<?phpimport_request_variables('gP','r_'); // imports request variables - you may or may not have to do this$f=fopen('feedback.txt','a'); // opens feedback.txt for appendingfwrite($f,"$r_name\n$r_email\n\n$r_content\n=======================\n"); // adds stuff to the file, assuming the fields are called "name", "email" and "content"fclose($f);?>



Should the php file be nothing BUT php, because I've got the regular HTML of my site which has the thank you comment and stuff there as well...
Title: Re: Anybody know PHP?
Post by: Migs on Thu 13/05/2004 22:07:30
Quote from: Os àšltimo Quão Queijo Raspado De Macaco Burro ^_^ on Thu 13/05/2004 00:34:09Should the php file be nothing BUT php, because I've got the regular HTML of my site which has the thank you comment and stuff there as well...

Not if you don't want to.Ã,  Just keep the HTML outside the <? ?>s.Ã,  If you want to keep the two separate, you can insert

<?php require ("feedback.php"); ?>


when you need to, but it will effectively "insert" the whole PHP file.
Title: Re: Anybody know PHP? (woohoo, working now! thanks guys!)
Post by: LordHart on Thu 13/05/2004 22:20:55
Wouldn't that be include, not require? ???
Title: Re: Anybody know PHP? (woohoo, working now! thanks guys!)
Post by: Ishmael on Fri 14/05/2004 09:39:30
I thought so too...
Title: Re: Anybody know PHP? (woohoo, working now! thanks guys!)
Post by: Fuzzpilz on Fri 14/05/2004 10:19:18
include and require do basically the same thing, but behave differently on failure. include produces a warning, require a fatal error.
Title: Re: Anybody know PHP? (woohoo, working now! thanks guys!)
Post by: Ishmael on Fri 14/05/2004 13:53:29
D'oh, of cource... I had read that, but ofcource I didn't remember... require is better in this case then, I think too...