Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 10th, 2005, 9:12 PM   #1
thechristelegacy
Expert Programmer
 
thechristelegacy's Avatar
 
Join Date: Jul 2004
Location: Somerset, Pa
Posts: 708
Rep Power: 5 thechristelegacy is on a distinguished road
Send a message via AIM to thechristelegacy Send a message via MSN to thechristelegacy
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.
thechristelegacy is offline   Reply With Quote
Old Nov 10th, 2005, 9:35 PM   #2
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 6 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
You might want to check your PHP version, if it's not PHP5 it doesn't have it...

http://www.php.net/fopen
__________________

tempest is offline   Reply With Quote
Old Nov 10th, 2005, 9:37 PM   #3
thechristelegacy
Expert Programmer
 
thechristelegacy's Avatar
 
Join Date: Jul 2004
Location: Somerset, Pa
Posts: 708
Rep Power: 5 thechristelegacy is on a distinguished road
Send a message via AIM to thechristelegacy Send a message via MSN to thechristelegacy
Thanks for the reply, it's not php5, I am going to try out fwrite(), I'll let you know on the results.
thechristelegacy is offline   Reply With Quote
Old Nov 10th, 2005, 10:14 PM   #4
thechristelegacy
Expert Programmer
 
thechristelegacy's Avatar
 
Join Date: Jul 2004
Location: Somerset, Pa
Posts: 708
Rep Power: 5 thechristelegacy is on a distinguished road
Send a message via AIM to thechristelegacy Send a message via MSN to thechristelegacy
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]
thechristelegacy is offline   Reply With Quote
Old Nov 10th, 2005, 10:20 PM   #5
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 6 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
You have been PM'd about security.
__________________

tempest is offline   Reply With Quote
Old Nov 11th, 2005, 12:04 AM   #6
thechristelegacy
Expert Programmer
 
thechristelegacy's Avatar
 
Join Date: Jul 2004
Location: Somerset, Pa
Posts: 708
Rep Power: 5 thechristelegacy is on a distinguished road
Send a message via AIM to thechristelegacy Send a message via MSN to thechristelegacy
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.
thechristelegacy is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:48 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC