Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
ok even simpler... is there a PHP script that can take a user's comments from a small text box and post straight to an HTML file? really simple
sean

Simpler than what? Yes there is a script that can do as you requested... plastered all over the internet. If it's simple, why the question?
At any rate, I don't think this is homework, because I don't know of anyone teaching PHP around here... lol.. I am feeling a little easy going tonight... So here is a few code segments that will get you on your way...
The HTML file --->
<form method="post" action="tohtml.php">
Name: <input name="name" type="text" /><br />
Message:<br />
<textarea name="message" rows="15" cols="40">
</textarea><br />
<input type="submit" />
</form>
The PHP script ---><?php
$name = $_REQUEST['name'] ;
$message = $_REQUEST['message'] ;
echo "$name said $message";
?>---
Since this is deemed easy by you, you can take that line of the PHP script and redirect it to an HTML file. You're right, it is easy :)Infinite Recursion

See what you have done... lol. I actually enjoyed that... now I went off and wrote a guestbook in PHP and toying with the idea of writing a forum in PHP... I wonder if that's a bad idea. hmmm.
Infinite Recursion

I knew I should have answered that when I had the chance! Now IR went off and had himself a good time. heh, if you want a slight challenge IR, write your forums using a MySQL database but without using a single PHP MySQL function, and no file stuff either.
-Micah

Micah, now ya know I am busy doing all of the students' homework and emailing it to them. Now you want me to go and write a forum in PHP using MySQL database without PHP MySQL functions, nor file IO... come on man... I did pretty good just to get it working with MySQL now you want me to tear it all apart :(
hahaha... have you done that before?
Infinite Recursion

You guys are sick. I mean seriously deranged. If God didn't want us to use built-in mySQL functions, then he wouldn't have created them. Same goes double for File IO.
Back on topic, say you wanted to post the input to an html file, as sean mentioned, but I assumed he meant append to an html file, like you would for a forum. Then wouldn't you either have to take out the closing BODY and HTML tags, then add the new post, then add the closing BODY and HTML tags to finish it off, or just have the php script append to a file that just has the body of the html page and another script to read it in and put on the html on top and bottom to make it valid HTML? I chose the second approach on my own forum in perl...Just File IO though, no mySQL.
IR - I enjoyed the homework stab.
-SN

lol, it was just to make it a little more challenging. You know...more fun:) It can be done using sockets, and that's not too terribly difficult. But IR, since your're busy doing ppls homework dont worry about it.
Sick?!? Sick is finding pics of me in a speedo posing with a naked commie. I won't name any names...
-Micah

Ancient chinese proverb:
"He who accidentally sees photos of sick people doing sick things is not as sick as the people in the photos."

Well, I'm taking a break from doing other peoples' homework for them and emailing it to them... So I decided to elaborate a bit on the dingy little PHP forum I made.
When I wrote my forum prototype earlier in response to this thread. I had three files, one file that contained the form for name and message, then my php script to write to my msgboard.html, then the msgboard.html that had the initial <BODY ...> and a few other tags.. My PHP script just appended the messages on to the msgboard.html file under the initial HTML tags (title, headings, etc)... I didn't finish the HTML closing, etc... so it probably isn't considered valid HTML, but its functional...
SN, I wonder if God is a programmer... lolMicah, nothing wrong with naked commies... dunno about the speedo deal though... lol
Infinite Recursion

IR-
You only think there's nothing wrong with naked commies cause you didn't see them while trying to help somebody then get mocked for it.((GASP)) Dost mine eyes deceive me? IR doesn't think valid HTML is important??? tsk tsk tsk, you'll never rule the world with that attitude. ;-)
-SN

SN: That particular naked commie was just a bad selection ;)
Of course valid HTML is important... notice I used the term "forum prototype" :) I'm sure HTML validation is just as easy as the rest of the forum construction. Besides, I gave up ruling the world, I just want to put a dent in the economy and be an underling for the new world leader... lol
Infinite Recursion

Ok.. :) Due to pressure... I have wrote my PHP script to generate valid HTML code. More or less, it takes the HTML file (before the next post) and strips one line away at the end of it. This line contains me ... After the post, that line is added back, simple enough I suppose. Sort of time consuming, being that I have only been using PHP for about 2 weeks... lol At any rate, I have conformed to the standars... ;)
Infinite Recursion

Speaking of errors:
The reference to "me" in the post above suppose to be the ending syntax of BODY and HTML. Also, I conformed to the standards, not the "standars"..
lol

Sean, to answer your email regarding more details for the file i/o:
The reference to the HTML file would be within my tohtml.php script. To write to a file... use:
$filename = 'myfile.html';
$fp = fopen($filename, "a");
$write = fputs($fp, $myVariable);
fclose($fp);If you have any other concerns, please feel free to post a new thread. I check the forums more than I check this particular email address.
Good luck!
Infinite Recursion

so if i want the submitted text that the user is submitting go to a file called index.htm, which is the page the submit box is on, i should change the 'myfile.html' to 'index.htm'?
sean

You have 3 files...
Name them as you please...post.html (contains the submit box, etc)
process.php (php script to write to HTML file
myfile.html (the file to write your input box contents to)Infinite Recursion

ok go to www.davishightuesday.com and click on the button that says "groupies" and on the bottom of the page is the submit box. this is currently what my php script is:

I don't see your PHP script... it may not have been imported to the forum correctly...
When trying to use your groupies script... here is the problem I encountered.
Parse error: parse error, expecting `T_VARIABLE' or `'$'' in /home/pseudo/public_html/groupies/tohtml.php on line 5
Regards,
Infinite Recursion

yeah thats what im getting as well... here is how this is currently set up:
index.htm has the submit box on it...
tohtml.php has this:
and myfile.html does not exist. is there something wrong with the php file?sean

Sean,
Your line
$fp = fopen($"myfile.html", "name");needs to read
$fp = fopen($filename, "a");The first change should be for an obvious reason, the last change is because "a" is not a name of choice, it is an instruction... in this case it is refering to "append" for the file I/O.
Regards,
Infinite Recursion

well, a whole new mess of problems... take a look. i updated the www.davishightuesday.com/tohtml.txt so you can see what the php file currently reads.
sean
www.davishightuesday.com=>click on groupies

Warning: fopen(myfile.html): failed to open stream: Permission denied in /home/pseudo/public_html/groupies/tohtml.php on line 5
Warning: fputs(): supplied argument is not a valid stream resource in /home/pseudo/public_html/groupies/tohtml.php on line 6
Both of these problems result in the fact that you do not have permissions set for each file. I'm not sure what OS you are running but you may want to try the following, if its Linux: all HTML files and your PHP script need READ (chmod a+r myhtmlfile.html) permission, your PHP script needs execute permission (chmod a+x myphpfile.php). Your HTML file that you are writing to needs WRITE permissions established. (chmod a+w myfile.html)...
---------
Fatal error: Call to undefined function: () in /home/pseudo/public_html/groupies/tohtml.php on line 7This error is generated because you do not have a value being assigned to your variable that you are trying to add to your file. In other words, $myVariable is NULL and needs a value.
Try those out...
Infinite Recursion

The value would be what ever you wanted to be sent to the HTML file. In other words, the HTML file's content.
IR

Yes, that's right.
You aquire that info into the PHP script when the form is submitted via the Post Action in your HTML file. You will have to call upon those values, assign them into strings, $myVariable, etc... and save them to your new HTML file.IR

forgive me for sounding dumb, but if im submitting a vaule from the text box then why is it giving me that error?
sean

You get that error because you are not assigning the value that you get from the text box to the variable, before you try to write the variable to your html file.
You need a line variable request line, to acquire the value of the text box in the PHP script so you can write it to the html file. As it, stands you aren't applying a value to the variable before you try to write it out.
IR

hey, first id like to thank you for all your help... but i have one more thing to ask of you... can you give me an example of what a good variable would be and where to put it?
thanks a bunch
sean

No problem, perhaps you all can send down a complimentary cd of your band's music ;)
I assume you want to add the name from your groupies form to the fan list... the form on your groupies section only has one component and that is a name text box named 'name'...
So in your PHP script you can have a variable...
//this will get the variable value from the
//form and into the php script
$myVariable = $_REQUEST['name'];$filename = 'myfile.html';
$fp = fopen($filename, "a");
$write = fputs($fp, $myVariable);
fclose($fp);This will append the name from your groupies form to a list of names located at 'myfile.html'
Regards,
Infinite Recursion

![]() |
Forum etiquette
|
Realistic Programs
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |