PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
benslayton
Forum Newbie
Posts: 12 Joined: Tue Jun 06, 2006 3:08 pm
Post
by benslayton » Tue Jun 06, 2006 3:31 pm
I have 3 php pages. Index.php, add.php, and sent.php. Basically you add comments to the index.php. But thats it it adds them and I need it to replace it. You can view it here
http://benslayton.awardspace.com
*index.php
Code: Select all
<html>
<head>
<title>Comment Demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<div align="center">
<div align="left">
<table width="80%" border="" cellspacing="0" cellpadding="0">
<tr>
<td align="left">
<?php
if ($file = @file_get_contents("comments.phpdata")) {
echo $file."\n";
}
else {echo "Sorry, but no comments were found.";}
?>
</td>
</tr>
</table>
</div>
<p align="left"><a href="add.php">Add Comment</a></p>
</div>
</body>
</html>
*add.php
Code: Select all
<html>
<head>
<title>Add Comment Demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<div align="center">
<p><font size="+1">Add Comment Demo:</font></p>
<form name="form1" method="post" action="sent.php">
<textarea name="comment" cols="60" rows="10"></textarea><br>
<input type="submit" value="submit"> - <input type="reset" value="reset">
</form>
<a href="index.php">Back</a>
</div>
</body>
</html>
*sent.php
Code: Select all
<?php
$filename = "comments.phpdata";
if ($name = stripslashes($_POST['comment'])) {
$comment = str_replace("<","<",$comment); //security
$comment = str_replace(">", ">", $comment); //security
if (strlen(@file_get_contents($filename)) > 0) $hr = "\n<hr>";
$add = "<br>".$comment;
$comments = @file_get_contents($filename).$add;
$file = @fopen($filename, "w+");
@fwrite($file, $comments);
@fclose($file);
$message = "Your comment was successfully added.<br>Redirecting to index.php";
}
else {
$message = "You either entered no data or it was entered incorrectly.<br>Redirecting to index.php";
}
?>
<html>
<head>
<title>Comment Added Demo</title>
<meta http-equiv="refresh" content="3;url=index.php">
</head>
<body>
<div align="center">
<p><font size="+1">Comment Added Demo:</font></p>
<?php echo $message; ?>
</div>
</body>
</html>
please help... Thank you!!
PrObLeM
Forum Contributor
Posts: 418 Joined: Sun Mar 07, 2004 2:30 pm
Location: Mesa, AZ
Contact:
Post
by PrObLeM » Tue Jun 06, 2006 3:42 pm
if you just want to overwrite the file then do this: (i think r+b is the right one.)
benslayton
Forum Newbie
Posts: 12 Joined: Tue Jun 06, 2006 3:08 pm
Post
by benslayton » Tue Jun 06, 2006 3:50 pm
Thanks but still it doesnt work.
PrObLeM
Forum Contributor
Posts: 418 Joined: Sun Mar 07, 2004 2:30 pm
Location: Mesa, AZ
Contact:
Post
by PrObLeM » Tue Jun 06, 2006 3:53 pm
sorry, this should work now.
Code: Select all
$filename = "comments.phpdata";
if ($name = stripslashes($_POST['comment'])) {
$comment = str_replace("<","<",$comment); //security
$comment = str_replace(">", ">", $comment); //security
$file = @fopen($filename, "w+");
@fwrite($file, $comment);
@fclose($file);
$message = "Your comment was successfully added.<br>Redirecting to index.php";
}
else {
$message = "You either entered no data or it was entered incorrectly.<br>Redirecting to index.php";
}
benslayton
Forum Newbie
Posts: 12 Joined: Tue Jun 06, 2006 3:08 pm
Post
by benslayton » Tue Jun 06, 2006 4:01 pm
thanks that works!!!! Now since that is over with i need the text box to automatically bring the contents back from the index page. Ex. if the index page Says" This Is working" When you log onto the add page I need the text on index to come up, in the text box.
Hope thats not confusing.
benslayton
Forum Newbie
Posts: 12 Joined: Tue Jun 06, 2006 3:08 pm
Post
by benslayton » Tue Jun 06, 2006 4:19 pm
Never mind on that 2nd question I found out how... But If you notice When I click enter on the keyboard it drops the sentence but it doesnt in the index page. Any suggestions???
a94060
Forum Regular
Posts: 543 Joined: Fri Feb 10, 2006 4:53 pm
Post
by a94060 » Tue Jun 06, 2006 7:55 pm
PrObLeM wrote: sorry, this should work now.
Code: Select all
$filename = "comments.phpdata";
if ($name = stripslashes($_POST['comment'])) {
$comment = str_replace("<","<",$comment); //security
$comment = str_replace(">", ">", $comment); //security
$file = @fopen($filename, "w+");
@fwrite($file, $comment);
@fclose($file);
$message = "Your comment was successfully added.<br>Redirecting to index.php";
}
else {
$message = "You either entered no data or it was entered incorrectly.<br>Redirecting to index.php";
}
not to hijack,but for the links you use str_replace,cant you use something like htmlspecialchars() on the comment?
benslayton
Forum Newbie
Posts: 12 Joined: Tue Jun 06, 2006 3:08 pm
Post
by benslayton » Tue Jun 06, 2006 10:18 pm
Ok that dont work. Please help me with this
I am using A WYSIWYG editor. But If I want the text bold or impact. It actually writes the code out, how do I fix that?????
Please help Very Important...
benslayton
Forum Newbie
Posts: 12 Joined: Tue Jun 06, 2006 3:08 pm
Post
by benslayton » Wed Jun 07, 2006 2:21 pm
I figured that last post out. Now I need to know how to fix the popups, like when you click to add a color, or a hyperlink. Anyone know how?????
a94060
Forum Regular
Posts: 543 Joined: Fri Feb 10, 2006 4:53 pm
Post
by a94060 » Wed Jun 07, 2006 2:34 pm
what do you mean? do those popups for the color not come up or something?
benslayton
Forum Newbie
Posts: 12 Joined: Tue Jun 06, 2006 3:08 pm
Post
by benslayton » Wed Jun 07, 2006 3:21 pm
They come up. They just dont add the color.... Or the hyperlink, or a table... etc....