某坛友需要标题查重功能,当然之前小编也写了相关教程的!不过经过坛友反应只查询了已审核的文章,没有查询待审核的文章。那小编就开始修复下代码吗?让功能更完善吧!下面就开始优雅的抒写我们的代码!注:输出是json,请自行AJAX对接。
- <?php
- require("../../class/connect.php");
- require("../../class/db_sql.php");
- require("../../data/dbcache/class.php");
- $link=db_connect();
- $empire=new mysqlquery();
- $return=array();
- if($_GET['title']!=strip_tags($_GET['title'])){
- $return['msg']=0;
- $return['text']="<span style='color:#f00'>非法字符已被清空!</span>";
- echo json_encode($return);
- exit;
- };
- $title=RepPostVar($_GET['title']);
- $classid=intval($_GET['classid']);
- $id=intval($_GET['id']);
- $tbname=$class_r[$classid]['tbname'];
- if(strlen($title)<1||strlen($title)>100){
- $return['msg']=1;
- $return['text']="";
- echo json_encode($return);
- exit;
- }else{
- $w=$empire->gettotal("select count(*) as total from {$dbtbpre}ecms_$tbname where title='$title' and id<>$id limit 1");
- $w+=$empire->gettotal("select count(*) as total from {$dbtbpre}ecms_$tbname_check where title='$title' and id<>$id limit 1");
- if(!$w){
- $return['msg']=2;
- $return['text']="<span style='color:#808080'><b>^_^没重复<b></span>";
- echo json_encode($return);
- exit;
- }else{
- $return['msg']=7;
- $return['text']="<span style='color:#f00'><b>标题重复!<b></span>";
- echo json_encode($return);
- exit;
- }
- }
- db_close();
- $empire=null;