这前面的代码,$arr不是一个空数组吗,后面还怎么预处理?
header(...);
require_once('connect.php');
require_once('comment.class.php');
$arr=array(); //这里这个$arr就是空数组了
$res=Comment::validate($arr); //空数组进行FILTER过滤有意义吗
这下面的预处理操作,$arr还是空数组,这些怎么回事,
顺带一提,AJAX也不懂,路径上没有
header(...);
require_once('connect.php');
require_once('comment.class.php');
$arr=array(); //这里这个$arr就是空数组了
$res=Comment::validate($arr); //空数组进行FILTER过滤有意义吗
这下面的预处理操作,$arr还是空数组,这些怎么回事,
顺带一提,AJAX也不懂,路径上没有
2016-12-09
//这是output方法
public function output(){
if($this->data['url']){
$link_start="<a href='".$this->data['url']."' target='_blank'>";
$link_end="</a>";
}else {
$link_start='';
$link_end='';
}
$dateStr=date("Y年m月d日 H:i:s",$this->data['pubTime']);
$res=<<<EOF
<div class='comment'>
<div class='face'>
{$link_start}
<img width='50' height='50' src="img/{$this->data['face']}.jpg" alt="" />
{$link_end}
</div>
<div class='username'>
{$link_start}
{$this->data['username']}
{$link_end}
</div>
<div class='date' title='发布于{$dateStr}'>
{$dateStr}
</div>
<p>{$this->data['content']}</p>
</div>
EOF;
return $res;
}
//这个是index.php页面
<?php
require_once('connect.php');
require_once('comment.class.php');
$sql="SELECT username,email,url,face,content,pubTime FROM comments";
$mysqli_result=$mysqli->query($sql);
if($mysqli_result&& $mysqli_result->num_rows>0){
while($row=$mysqli_result->fetch_assoc()){
$comments[]=new Comment($row); //创建一个对象,将$row作为参数写入构造函数
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<title>Document</title>
<link rel="stylesheet" type="text/css" href="style/style.css" />
</head>
<body>
<h1>慕课网评论系统</h1>
<div id='main'>
<?php
foreach($comments as $val){
echo $val->output();
}
?>
<div id='addCommentContainer'>
<form id="addCommentForm" method="post" action="comment.class.php">
<div>
<label for="username">昵称</label>
<input type="text" name="username" id="username" required='required' placeholder='请输入您的昵称'/>
<label for="face">头像</label>
<div id='face'>
<input type="radio" name="face" checked='checked' value="1" /><img src="img/1.jpg" alt="" width='50' height='50' />
<input type="radio" name="face" value="2" /><img src="img/2.jpg" alt="" width='50' height='50' />
<input type="radio" name="face" value="3" /><img src="img/3.jpg" alt="" width='50' height='50' />
<input type="radio" name="face" value="4" /><img src="img/4.jpg" alt="" width='50' height='50' />
<input type="radio" name="face" value="5" /><img src="img/5.jpg" alt="" width='50' height='50' />
</div>
<label for="email">邮箱</label>
<input type="email" name="email" id="email" required='required' placeholder='请输入合法邮箱'/>
<label for="url">个人博客</label>
<input type="url" name="url" id="url" />
<label for="content">评论内容</label>
<textarea name="content" id="content" cols="20" rows="5" required='required' placeholder='请输入您的评论...'></textarea>
<input type="submit" id="submit" value="发布评论" />
</div>
</form>
</div>
</div>
<script type="text/javascript" src="script/jquery.min.js"></script>
<script type="text/javascript" src="script/comment.js"></script>
</body>
</html>
$(document).ready(function(){
//这个是comments.js页面
//此标志用于标志是否提交,防止多次提交
var flag=false;
//监测是否提交
$('#addCommentForm').submit(function(e){
//阻止表单的自动提交
e.preventDefault();
if(flag) return false;
flag = true;
$('#submit').val('发布...');
$('span.error').remove();
//通过Ajax发送数据
$.post('doAction.php',$(this).serialize(),function(msg){
flag = false;
$('#submit').val('发布评论');
if(msg.status){
$(msg.html).hide().insertBefore('#addCommentContainer').slideDown();
$('#content').val('');
}
else {
$.each(msg.errors,function(k,v){
$('label[for='+k+']').append('<span class="error">'+v+'</span>');
});
}
},'json');
});
});
举报