![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Expert Programmer
|
Blog trouble
I've had a personel blog for a while, but one of the things that it lacks is the ability to add comments. So I'm working on a new version of my blog so that one will be able to add comments. I have enough php to retrieve data from the form, but it's when I try to write the data to a file it fails showing "Fatal error: Call to undefined function: file_put_contents() in /home/www/bigtonyc/blog/filewrite.php on line 19"
Here is the form code: <form method="get" action="filewrite.php" name="commentAdd"><textarea cols="30" rows="3" name="comment"></textarea> <p> <input name="page" value="oct1305.html" type="hidden"><input value="Submit" name="submit" type="submit"></p> </form> and the php: [php] <html> <head> <title> Comments page. </title> </head> <body> Adding comment, will redirect back to original page. If the page does not refresh, please click the link below.<br /> <br /> <a href="http://www.bigtonyc.com/blog/index.html">Back</a> <br /> <br /> Comment: <?php echo $_GET["comment"]; ?>.<br /> Page: <?php echo $_GET["page"]; ?>.<br /> <?php $filename = $_GET["page"]; ?> <?php $data = $_GET["comment"]; ?> <?php file_put_contents($filename, $data); ?> </body> </html> [/php] You can try it out for yourself if it will help you figure out the error. www.bigtonyc.com/blog/index.html Thanks for any advice in advance :-). I've never even looked at php before tonight, so i'm really not sure where I'm going wrong. |
|
|
|
|
|
#2 |
|
Programming Guru
![]() |
You might want to check your PHP version, if it's not PHP5 it doesn't have it...
http://www.php.net/fopen
__________________
|
|
|
|
|
|
#3 |
|
Expert Programmer
|
Thanks for the reply, it's not php5, I am going to try out fwrite(), I'll let you know on the results.
|
|
|
|
|
|
#4 |
|
Expert Programmer
|
Ah it works, here is what I used instead.
[php] Comment: <?php echo $_GET["comment"]; ?>.<br /> Page: <?php echo $_GET["page"]; ?>.<br /> <?php $filename = $_GET["page"]; $data = $_GET["comment"]; $name = $_GET["name"]; $br = "<br />"; $brs = "<br /><br />"; $handle = fopen($filename, "a"); fwrite($handle, $name); fwrite($handle, $br); fwrite($handle, $data); fwrite($handle, $brs); fclose($handle); ?> [/php] |
|
|
|
|
|
#5 |
|
Programming Guru
![]() |
You have been PM'd about security.
__________________
|
|
|
|
|
|
#6 |
|
Expert Programmer
|
Thanks tempest for helping me out
![]() Final results [php] <html> <head> <META HTTP-EQUIV="refresh" CONTENT="1;URL=http://www.bigtonyc.com/blog/index.html"> <title> Comments page. </title> </head> <body> Adding comment, will redirect back to original page. If the page does not refresh, please click the link below.<br /> <br /> <a href="http://www.bigtonyc.com/blog/index.html">Back</a> <br /> <br /> Comment: <?php echo $_GET["comment"]; ?>.<br /> Page: <?php echo $_GET["page"]; ?>.<br /> <?php $filename = $_GET["page"]; $data = $_GET["comment"]; $name = $_GET["name"]; $br = "<br />"; $brs = "<br /><br />"; $pages = array('oct3105.html', 'nov1005.html'); if( in_array($filename, $pages) ) { $handle = fopen($filename, "a"); fwrite($handle, htmlspecialchars($name)); fwrite($handle, $br); fwrite($handle, htmlspecialchars($data)); fwrite($handle, $brs); fclose($handle); } else { die("Nice Try"); } ?> </body> </html> [/php] Last edited by thechristelegacy; Nov 11th, 2005 at 12:17 AM. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|