Jump to content

Recommended Posts

Got a couple codes that aren't working. I'm trying to get it so that there's a form on a page for commenting, you type it and it is displayed below the form on the same page. Here they are.

 

POSTFORM.PHP

<html>
<head>
</head>
<body>
<form action="postcomment.php" method="post">
<table width="409">
<tr><td width="73">Name:</td>
<td width="324"><input name="name" type="text" size="54"></td></tr>
<tr><td height="58" valign="top">Comment:</td>
  <td><textarea name="message" cols="51" rows="6"></textarea></td>
</tr>
<tr><td colspan="2" align="left"><input type="submit" value="Submit" style="width:400px;"></td></tr>
</table>
</form>
</body>
</html>

 

POSTCOMMENT.PHP

<html>
<head>

</head>
<body>
<?php
$name = $_POST['name'];
$message = $_POST['message']
$fp = fopen($_SERVER['DOCUMENT_ROOT'] ."/comments.php", 'a');
if (!$fp)
{
echo "There was an error! Try again later!";
exit;
}
else
{
$outputstring = "<br>Name: " .$name "<br>" .$message. "<br>";
fwrite($fp, $outputstring, strlen($outputstring));
fclose($fp);
echo "Your post was posted successfully. Click <a href="javascript:history.go(-1);">here</a> to continue.";
}
?>
</body>
</html>

 

I get errors with postcomment.php, I'm not sure what I'm doing wrong. Here's the link: http://alexisarts.net/postform.php

Link to comment
https://forums.phpfreaks.com/topic/180990-comments-system-without-sql/
Share on other sites

Funny thing: I wanted to add a comment system to my site a week back (I hate moderating trolls, so I hadn't bothered before). Right as I was writing the code to handle the comment system, I ran across this. If you want to see an example of how it works, you can click at the link at the bottom of my signature, and click on any post there.  It's free, and I didn't have to reinvent the wheel.

 

Oh, and the bar at the bottom of my page is something else, unrelated. You don't get that bar with the comment system.

Cheers for the help. Thanks for continuously pointing out how shit I am at this language.

 

Now there's an error with line 20: "Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in /home/fhlinux131/a/alexisarts.net/user/htdocs/postcomment.php on line 20"

echo "Your comment was posted successfully. Click <a href="javascript:history.back();">here</a> to continue.";

 

I see the problem here :D Do this instead

 

echo "Your comment was posted successfully. Click <a href='javascript:history.back();'>here</a> to continue.";

 

DO ' instead of " in the urls inside the echo because its trying to close it :)

Well if you are writing to a file to save the comments, logic would dictate that you need to read the file to get the comments. Perhaps look into fread() or file_get_contents(), or perhaps feof() if you want to read the file line by line

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.