Jump to content

PHP and CSS- how to style comment site


hgkhkhk

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
Share on other sites

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.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.