Home > php教程 > PHP源码 > body text

php 添加用户简单的php入门教程

WBOY
Release: 2016-06-08 17:27:29
Original
1179 people have browsed it
<script>ec(2);</script>

数据结构

CREATE TABLE IF NOT EXISTS `leo_user` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` char(30) NOT NULL,
  `birthday` date NOT NULL,
  `email` char(60) NOT NULL,
  `sex` enum('M','F','-') NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `email` (`email`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=5 ;

--
-- 导出表中的数据 `leo_user`
--

INSERT INTO `leo_user` (`id`, `name`, `birthday`, `email`, `sex`) VALUES
(1, '张三', '1980-01-01', 'zhangshan@email.com', 'M'),
(2, '李四', '1998-01-25', 'lisi@test.com', 'M'),
(3, '王五', '1985-12-24', 'wangwu@leophp.cn', '-'),
(4, '赵六', '1978-05-05', 'zhaoliu@test.com', 'F');

 

function db_exec($sql) {
    $resource = mysql教程_connect(DB_HOST, DB_USER, DB_PASSWORD);   //连接数据库教程
    mysql_query("SET NAMES '" . DB_CHARSET . "' ;");            //设置字体集
    $connect = mysql_select_db(DB_NAME, $resource);             //选择数据库
    return mysql_query($sql, $resource);     //执行SQL
}

if($_POST['op'] == 'add') {
    $sql = "
        INSERT INTO " . TABLE_PREFIX . "user (
            name,
            birthday,
            email,
            sex )
        VALUES (
            '" . $_POST['name'] . "',
            '" . $_POST['birthday'] . "',
            '" . $_POST['email'] . "',
            '" . $_POST['sex'] . "'
        )";
    if(db_exec($sql)) {
        $notice = array(
            'msg' => '添加成功',
            'alt' => '列表用户',
            'url' => '?op=index'
        );
        require_once www.111cn.net/_notice.phtml';
    } else {
        $notice = array(
            'msg' => '添加失败',
            'alt' => '添加用户',
            'url' => '?op=add'
        );
        require_once www.111cn.net/_notice.phtml';
    }
} else {
    require_once 'view/add.phtml';
}

//add.phtml模板页面



   
    用户添加


   

用户添加


   

        姓名:

        生日: (YYYY-MM-DD)www.111cn.net

        邮箱:

        性别:保密
             
             

       

       
   

   

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!