最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
php ajax 留言板
时间:2010-11-01 编辑:简简单单 来源:一聚教程网
*/
代码如下 | 复制代码 |
$link = @mysql_connect($db_host,$db_user,$db_pass) or die('unable to establish a db connection'); mysql_query("set names 'utf8'"); class comment '; } public static function validate(&$arr) { /* / this method is used to validate the data sent via ajax. / / it return true/false depending on whether the data is valid, and populates / the $arr array passed as a paremter (notice the ampersand above) with / either the valid input data, or the error messages. */ $errors = array(); $data = array(); // using the filter_input function introduced in php 5.2.0 if(!($data['email'] = filter_input(input_post,'email',filter_validate_email))) { $errors['email'] = 'please enter a valid email.'; } if(!($data['url'] = filter_input(input_post,'url',filter_validate_url))) { // if the url field was not populated with a valid url, // act as if no url was entered at all: $url = ''; } // using the filter with a custom callback function: if(!($data['body'] = filter_input(input_post,'body',filter_callback,array('options'=>'comment::validate_text')))) { $errors['body'] = 'please enter a comment body.'; } if(!($data['name'] = filter_input(input_post,'name',filter_callback,array('options'=>'comment::validate_text')))) { $errors['name'] = 'please enter a name.'; } if(!empty($errors)){ // if there are errors, copy the $errors array to $arr: $arr = $errors; return false; } // if the data is valid, sanitize all the data and copy it to $arr: foreach($data as $k=>$v){ $arr[$k] = mysql_real_escape_string($v); } // ensure that the email is lower case: $arr['email'] = strtolower(trim($arr['email'])); return true; } private static function validate_text($str) } $comments = array(); while($row = mysql_fetch_assoc($result)) ?>
css教程" href="styles.css" />
/* foreach($comments as $c){ ?> add a comment
|
数据库教程结构
代码如下 | 复制代码 |
-- create table `comments` ( |
-
上一个: php通用防注入与注入详细说明
相关文章
- PHP导出数据超时的优化建议解读 10-31
- PHP之mysql位运算解析 10-31
- Laravel实现登录跳转功能解析 10-31
- php双向队列解读 10-31
- Laravel异常上下文解决教程 10-24
- php数组查询元素位置方法介绍 10-24
'.$link_open.'
'.$link_close.'
'.$d['body'].'