• php懒人函数 自动添加数据


    简介:这是php懒人函数-- 自动添加数据的详细页面,介绍了和php,有关的知识、技巧、经验,和一些php源码等。

    class='pingjiaF' frameborder='0' src='http://biancheng.dnbcw.info/pingjia.php?id=338994' scrolling='no'>

    //自动插入数据函数 这个是简单的 有需要大家自己扩展

    $table 表名

    $arr 字段
    method 提交表单方式


     function autoInsert($table,$arr=array(),$method='post')
     {
      $sql="insert into ".DB_TBLPRE."$table set  ";
      $var="";
      print_r($arr);
      if(empty($arr)) $arr=$_POST?$_POST:$_GET;
      if(empty($arr)) return false;
      $ct=count($arr)-1;
      foreach($arr as $k=> $v)
      {
       $vtype=0;
       if(is_array($v))
       {   
        $vtype=@$v[1];
        $v=$v[0];
       }
       if($method=='post')
       {
        if(is_int($_POST[$v]))
        {
         $_POST[$v]=intval($_POST[$v]);
        }elseif(is_float($_POST[$v]))
        {
         $_POST[$v]=float($_POST[$v]);
        }elseif(is_string($_POST[$v]))
        {
         //等于1 为保存html 默认不保存html
         if(!$vtype)
         {
          $_POST[$v]=htmlspecialchars($_POST[$v]);
         } 
        
        }
        
        
        $var.= "$v = '$_POST[$v]' ".($k<$ct?",":"");
       }else
       {
        if(is_int($_GET[$v]))
        {
         $_GET[$v]=intval($_GET[$v]);
        }elseif(is_float($_GET[$v]))
        {
         $_GET[$v]=float($_GET[$v]);
        }elseif(is_string($_GET[$v]))
        {
         //等于1 为保存html 默认不保存html
         if(!$vtype)
         {
          $_GET[$v]=htmlspecialchars($_GET[$v]);
         } 
        
        }
        $var .="$v= '$_GET[$v]' ".($k<$ct?",":"");
       }
      }
      $sql.=$var;
      
      $this->query($sql);
      return $this->insert_id();
     }

    爱J2EE关注Java迈克尔杰克逊视频站JSON在线工具

    http://biancheng.dnbcw.info/php/338994.html pageNo:8
  • 相关阅读:
    复利计算器2.01
    复利计算器2.0
    0429团队3.0
    0428 团队项目合作2.0作业
    "数学口袋精灵"bug
    操作系统-实验2
    博客评论
    复利计算升级
    0408 结对合作
    0406复利计算5.0
  • 原文地址:https://www.cnblogs.com/ooooo/p/2246198.html
Copyright © 2020-2023  润新知