简单的ajax评论完整代码
数据库结构CREATE TABLE `comments` (
`id` int(10) unsigned NOT NULL auto_increment,
`name` varchar(128) collate utf8_unicode_ci NOT NULL default '',
`url` varchar(255) collate utf8_unicode_ci NOT NULL default '',
`email` varchar(255) collate utf8_unicode_ci NOT NULL default '',
`body` text collate utf8_unicode_ci NOT NULL,
`dt` timestamp NOT NULL default CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1;
PHP Code
- <?PHP
- //Errorreporting:
- error_reporting(E_ALL^E_NOTICE);
- include"conn.PHP";
- include"comment.class.PHP";
- /*
- /Selectallthecommentsandpopulatethe$commentsarraywithobjects
- */
- $comments=array();
- $result=MysqL_query("SELECT*FROMcommentsORDERBYidASC");
- while($row=MysqL_fetch_assoc($result))
- {
- $comments[]=newComment($row);
- }
- ?>
<divid="main">
/*
/Outputthecommentsonebyone:
*/
foreach($commentsas$c){
echo$c->markup();
}
?>
<divid="addCommentContainer">
<p>AddaComment</p>
<formid="addCommentForm"method="post"action="">
<div>
<labelfor="name">YourName</label>
<inputtype="text"name="name"id="name"/>
<labelfor="email">YourEmail</label>
<inputtype="text"name="email"id="email"/>
<labelfor="url">Website(notrequired)</label>
<inputtype="text"name="url"id="url"/>
<labelfor="body">CommentBody</label>
<textareaname="body"id="body"cols="20"rows="5"></textarea>
<inputtype="submit"id="submit"value="Submit"/>
</div>
</form>
</div>