Zend - The PHP Company




Discussion

Add Code


Comment Form  

Type: code fragment
Added by: rlynch
Entered: 16/05/2000
Last modified: 01/11/2007
Rating: *** (4 votes)
Views: 10789
Simple example of how to add comments to your pages not unlike the user's annotated manual at http://www.php.net/ You may want to use URLs as a key instead of productid to be even more like PHP's annotation facility.


Untested code off the top of my head:

CREATE table comments(
  productid int4,
  comment text
);

product.php3
<?php
  $productid 
42;
  
$product_name 'widget';
  echo 
"<A HREF=comment.php3?productid=$productid>Comments</A> about $product_name<BR>n";
  
$comments mysql_query("select comment from comments where productid = $productid") or die(mysql_error());
  while (list(
$comment) = mysql_fetch_row($comments)){
    echo 
$comments"<HR>";
  }
?>

comment.php3
<?php
  
if (isset($submit)){
    
mysql_query("INSERT into comments(productid, comment) values($productid, '$comments')") or die(mysql_error());
    echo 
"Thank you for your comment.<BR>n";
  }
?>
<FORM ACTION=comment.php3 METHOD=POST>
  <TEXTAREA NAME=comments WRAP=VIRTUAL></TEXTAREA><BR>
  <INPUT TYPE=SUBMIT NAME=submit>
</FORM>


Usage Example


See the example


Rate This Script





Search



This Category All Categories