• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

Add Your Coments script

Pimpin Monkey

New Member
I wanted to know if someone could make me a Add Your Comments script that I could use in my news section. Free and PHP perfered!
 
like a form with name, email and comments? some people call that a guestbook... ;)

this is among the very first things i wrote while learning php so its probably not coded in the best manner but it works (if you have access to mysql that is), i have to go in a minute otherwise i would have written a little script like that, someone else probably will before i get home from work... but if they don´t, here you go...

dbconnect.php
PHP:
<?php

$db = "yourdb";
$dbusername = "yourdbusername";
$dbpassword = "yourdbpassword";
$table = "comments";

//  connecting to MySQL

$conn = mysql_connect("localhost", "$dbusername", "$dbpassword") or
	die("Count not connect to database");
echo "connected to database.<br>";

?>

maketables.php
PHP:
<?php

  include('dbconnect.php');

  //  selecting database

  mysql_select_db($db) or 
    die ("Could not select database");  
  echo "selcted database $db.<br>";  
 
  //  creating table here
 
  $query = "create table $table
      ( 
        name          varchar(40) null,
        email         varchar(40) null,
        comments      text null
      )";
  
  mysql_query ($query) or
     die (mysql_error());
  echo "created table $table";

?>

yournewspage.php
PHP:
<LINK REL="stylesheet" TYPE="text/css" HREF="123.css">
<?php

include('dbconnect.php');
  
//  selecting database

mysql_select_db($db);  
 
//  inserting info into table

if($submit == "Sign")
{
$query = "insert into $table
(name, email, comments) values ('$name', '$email', '$comments')";
mysql_query($query) or
die (mysql_error());
}
?>

<br><br>
<center>
<table width="500" bgcolor="#FFFFFF" cellpadding="0" cellspacing="0" border="1" bordercolor="#000000">
<tr>
<td width="500" align="center">

<table width="500" cellpadding="0" cellspacing="0" border="0">
<tr>
<td bgcolor="#DCDCDC" align="center" class="header">
» Add Your Comments «
</td>
</tr>
<tr>
<td align="center" class="menu">
<br>

<table>
<tr>
<td align="right">

<form action ="<?php echo $PHP_SELF; ?>" method="post">
Name : &nbsp; 
</td>
<td>
<input type="text" name="name"><br>
</td>
</tr>
<tr>
<td valign="top" align="right">
Email : &nbsp; 
</td>
<td>
<input type="text" name="email"><br>
</td>
</tr>
<tr>
<td valign="top" align="right">
Comments : &nbsp; 
</td>
<td>
<textarea name=comments cols=30 rows=4 wrap=virtual>
</textarea>
<br>
</td>
</tr>
<td> </td>
<td>
<input type=submit name=submit value="Sign">
<input type=reset name=reset value="Reset">
<br>
</td>
</tr>
</table>

</td>
</tr>
</table>


</td>
</tr>
</table>

<?php

//  displaying the contents of $table

echo '<br><br>
<center>
<table width="500" bgcolor="#FFFFFF" cellpadding="0" cellspacing="0" border="1" bordercolor="#000000">
<tr>
<td width="500" align="center">

<table width="500" cellpadding="0" cellspacing="0" border="0">
<tr>
<td bgcolor="#DCDCDC" align="center" class="header">
» Comments «
</td>
</tr>
<tr>
<td align="center" class="menu">'; 
$query = "select * from $table";
$result = mysql_query($query) or
     die(mysql_error());

echo "<br><br>";

while ($row = mysql_fetch_array($result))
  {
    echo '<table width="400" border="1" cellspacing="0" cellpadding="0">
<tr>
<td>

<table width="400" border="0" cellspacing="0" cellpadding="0">
<tr bgcolor="#DCDCDC">
<td align="right" valign="top" width="125"><b>Name : &nbsp; </b></td>
<td width="275" align="left" valign="top">';
    echo $row["name"];
    echo "</td>
</tr>";
    echo '<tr><td align="right" valign="top"><b>Email : &nbsp; </b></td>
<td>';
    echo $row["email"];
    echo "</td></tr>";
    echo '<tr bgcolor="#DCDCDC"><td align="right" valign="top"><b>Comments : &nbsp; </b></td>
<td>';
    echo $row["comments"];
    echo "</td></tr></table>
</td></tr></table><br><br>";
  }
?>

<br><br>
</td>
</tr>
</table>

</td>
</tr>
</table>

123.css
PHP:
A:link        {text-decoration: none; color: #72A4F6;}
A:visited     {text-decoration: none; color: #72A4F6;}
A:hover       {text-decoration: none; color: #000000; font-style: normal; text-decoration: underline;}
BODY          {scrollbar-face-color: #FFFFFF; scrollbar-shadow-color: #999999; scrollbar-highlight-color: #999999;
     	       scrollbar-3dlight-color: #999999; scrollbar-darkshadow-color: #999999; scrollbar-track-color: #999999;
     	       scrollbar-arrow-color: #FFFFFF; font-family: Times New Roman}
.header       {font-size: 20px; color: #000000; font-family: Verdana;}
.head2        {font-size: 12px; color: #FFFFFF; font-family: Verdana;}
.news         {font-size: 10px; font-family: Verdana;}
.menu         {font-size: 11px; font-family: Verdana;}

just replace the $db, $dbusername and $dbpassword values in dbconnect.php to your info... run maketables.php once and insert the code from yournewspage.php to the bottom of your newspage or wherever you want it (add the link rel tag between <head> and </head>... and then your good to go... well, you probably have to change the layout of the whole thing in yournewspage.php to fit your site...
 
Last edited:
Exactly Spec! Since it seem that no one can do that for me. Does anyone know of a News script that has that (one they've used before). I've tried a few at HotScripts.com that had that feature but none of them installed correctly.
 
Back
Top