Jump to content

PHP and CSS- how to style comment site


Go to solution Solved by requinix,

Recommended Posts

I am building a comment section for my system. While it is working successfully, I cannot seem to style the comments the way I want to. All the comments appear at the very left side of the screen. Essentially I want to bring them to the center, color the username, and maybe put a border around the username and comments. I have tried everything such as using span classes and div classes, but nothing is working. If someone could please tell me where to put the span or div classes, I would appreciate it. Thank you.

<?php

if($_POST) {
    $name = $_POST['name'];
	$content = $_POST['commentContent'];
	$handle = fopen("comments.html","a");
	fwrite($handle,"<b>" . $name . "</b>:<br/>" . $content . "<br/><br>");
	fclose($handle);
}
?>
	

<!doctype html>

<html>

</head>

<link rel="stylesheet" type="text/css" href="commentstyle.css">
<link rel="icon" href="Icon.jpg">

<title>Comment</title>

</head>

<body>

<div class="header">

<img class="icon" src="Icon.jpg"> 
<div class="search">Comment </div>

</div>

<a href="homepage.php"><span class="home">Homepage</span></a>

<div class="select">View comments</div>
<br>

<?php include "comments.html"; ?>

<hr>

<div class="box">
<form action = "" method = "POST">
Name:<br> <input type = "text" name = "name"><br/>
Comment: <textarea rows = "10" cols = "30" name = "commentContent"></textarea><br/>
<input type = "submit" value = "Submit"><br/>


</form>
</div>
</body>

</html>
Link to comment
https://forums.phpfreaks.com/topic/305640-php-and-css-how-to-style-comment-site/
Share on other sites

  • Solution

You have a much larger problem than just the styling of the comments: people can execute PHP code on your site, let alone put HTML (and Javascript) on your site.

 

Do you want people to write HTML? Please say no because allowing that is painful. Replace

with

and

fwrite($handle,"" . $name . ":
" . $content . "

");
with

fwrite($handle,"" . htmlspecialchars($name) . ":
" . htmlspecialchars($content) . "

");
Now go into your comments.html and make sure there isn't anything bad in it.

 

With that taken care of, find and fix the problem with your starting

tag. I expect the browser was able to recover gracefully from it, though, as you would have noticed otherwise.

 

 

Anyways,

 

If you need help with the appearance of your site then we need to see the HTML (your PHP isn't complicated so that's okay) and the CSS. Preferably with a link to the site, but don't provide a link until you do the comment thing I said above.

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.