fantasticham Posted November 10, 2009 Share Posted November 10, 2009 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 More sharing options...
sasa Posted November 10, 2009 Share Posted November 10, 2009 add ; to the end of line 8 Link to comment https://forums.phpfreaks.com/topic/180990-comments-system-without-sql/#findComment-955046 Share on other sites More sharing options...
fantasticham Posted November 10, 2009 Author Share Posted November 10, 2009 add ; to the end of line 8 I'm still getting this error: Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/fhlinux131/a/alexisarts.net/user/htdocs/postcomment.php on line 17 Link to comment https://forums.phpfreaks.com/topic/180990-comments-system-without-sql/#findComment-955059 Share on other sites More sharing options...
jonsjava Posted November 10, 2009 Share Posted November 10, 2009 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. Link to comment https://forums.phpfreaks.com/topic/180990-comments-system-without-sql/#findComment-955069 Share on other sites More sharing options...
Mchl Posted November 10, 2009 Share Posted November 10, 2009 echo "Your post was posted successfully. Click <a href="javascript:history.go(-1);">here</a> to continue."; Does this look right to you? Link to comment https://forums.phpfreaks.com/topic/180990-comments-system-without-sql/#findComment-955072 Share on other sites More sharing options...
jonsjava Posted November 10, 2009 Share Posted November 10, 2009 Nope. echo "Your post was posted successfully. Click <a href=\"javascript:history.go(-1);\">here</a> to continue."; Link to comment https://forums.phpfreaks.com/topic/180990-comments-system-without-sql/#findComment-955080 Share on other sites More sharing options...
fantasticham Posted November 10, 2009 Author Share Posted November 10, 2009 I replaced that with "javascript:history.back()" earlier. That isn't what's causing the error, anyway. Link to comment https://forums.phpfreaks.com/topic/180990-comments-system-without-sql/#findComment-955090 Share on other sites More sharing options...
Mchl Posted November 10, 2009 Share Posted November 10, 2009 This line is: $outputstring = "<br>Name: " .$name "<br>" .$message. "<br>"; Spot the missing dot Link to comment https://forums.phpfreaks.com/topic/180990-comments-system-without-sql/#findComment-955092 Share on other sites More sharing options...
Maq Posted November 10, 2009 Share Posted November 10, 2009 This line is: $outputstring = " Name: " .$name " " .$message. " "; Spot the missing dot Or spot the extra dots and quotes. $outputstring = " Name: $name $message "; Link to comment https://forums.phpfreaks.com/topic/180990-comments-system-without-sql/#findComment-955098 Share on other sites More sharing options...
Mchl Posted November 10, 2009 Share Posted November 10, 2009 Whichever suits you best Link to comment https://forums.phpfreaks.com/topic/180990-comments-system-without-sql/#findComment-955104 Share on other sites More sharing options...
fantasticham Posted November 10, 2009 Author Share Posted November 10, 2009 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" Link to comment https://forums.phpfreaks.com/topic/180990-comments-system-without-sql/#findComment-955112 Share on other sites More sharing options...
Mchl Posted November 10, 2009 Share Posted November 10, 2009 Which line is line 20? Link to comment https://forums.phpfreaks.com/topic/180990-comments-system-without-sql/#findComment-955113 Share on other sites More sharing options...
fantasticham Posted November 10, 2009 Author Share Posted November 10, 2009 echo "Your comment was posted successfully. Click <a href="javascript:history.back();">here</a> to continue."; Link to comment https://forums.phpfreaks.com/topic/180990-comments-system-without-sql/#findComment-955116 Share on other sites More sharing options...
Mchl Posted November 10, 2009 Share Posted November 10, 2009 jonsjava has already fixed it for you Link to comment https://forums.phpfreaks.com/topic/180990-comments-system-without-sql/#findComment-955119 Share on other sites More sharing options...
fantasticham Posted November 10, 2009 Author Share Posted November 10, 2009 so he did, sorry. aah, fuck, now the comments aren't appearing. http://alexisarts.net/postform.php Link to comment https://forums.phpfreaks.com/topic/180990-comments-system-without-sql/#findComment-955120 Share on other sites More sharing options...
Mchl Posted November 10, 2009 Share Posted November 10, 2009 Why would they? There's no code that would display them. Link to comment https://forums.phpfreaks.com/topic/180990-comments-system-without-sql/#findComment-955130 Share on other sites More sharing options...
fantasticham Posted November 10, 2009 Author Share Posted November 10, 2009 I'm really not sure how to go about writing that. I'm new to this and must be really annoying but I'm not sure how to connect all this stuff up. Link to comment https://forums.phpfreaks.com/topic/180990-comments-system-without-sql/#findComment-955189 Share on other sites More sharing options...
Kaboom Posted November 10, 2009 Share Posted November 10, 2009 echo "Your comment was posted successfully. Click <a href="javascript:history.back();">here</a> to continue."; I see the problem here 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 Link to comment https://forums.phpfreaks.com/topic/180990-comments-system-without-sql/#findComment-955193 Share on other sites More sharing options...
Mchl Posted November 10, 2009 Share Posted November 10, 2009 Yes. That is an alternative solution to the one posted above Link to comment https://forums.phpfreaks.com/topic/180990-comments-system-without-sql/#findComment-955194 Share on other sites More sharing options...
fantasticham Posted November 10, 2009 Author Share Posted November 10, 2009 Thanks, I got all that working, it's just figuring out how to display the comments now. How would I start? D: Link to comment https://forums.phpfreaks.com/topic/180990-comments-system-without-sql/#findComment-955204 Share on other sites More sharing options...
mikesta707 Posted November 10, 2009 Share Posted November 10, 2009 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 Link to comment https://forums.phpfreaks.com/topic/180990-comments-system-without-sql/#findComment-955208 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.