php 表单提交

<?php
header("Content-Type:text/html;   charset=utf8");


class config{
     public static function db() {
        $con = mysql_connect("localhost", "root", "root");
        mysql_query("set names utf8");
        mysql_select_db("yunnan12316", $con);
    }
}

class addData {
    
    private $_send;
    
    
    function alter($db,$post,$table) {
        $this->_send = $db;
        foreach ($_POST as $key => $value) {
            $array[] = "add " . $key . " varchar(220),";
        }
        $string = rtrim(implode(" ", $array), ",");
        $sql = "alter table ".$table." " . $string . "";
        mysql_query($sql);
    }
    
    function add($db,$post,$table) {
        $this->_send = $db;
        foreach ($post as $key => $value) {
            $k[] = $key;
            $v[] = "'" . $value . "'";
        }
        $key_db = implode(',', $k);
        $value_db = implode(',', $v);
        $sql = "INSERT INTO ".$table." (".$key_db.") VALUES (".$value_db.")";
        mysql_query($sql);
    }
        
}

/*
    table:qw_car,qw_goods
*/


$addData = new addData();
$post = @$_POST;
    if(@$post['price']==null){
        $addData->alter(config::db(),$post,'qw_car');
        $addData->add(config::db(),$post,'qw_car');
    }else{
        $addData->alter(config::db(),$post,'qw_goods');
        $addData->add(config::db(),$post,'qw_goods');
    }

 

posted @ 2016-09-22 16:23  fleam  阅读(164)  评论(0编辑  收藏  举报