listdemo.html负责显示,listModel.class.php负责从数据库存储数据和查找数据,mysql.class.php是操作数据库的类,但不直接使用,model类调用mysql,listmodel类继承model类,将数据库插入指定数据库,list.php将html文件引入,创建listmodel对象,向数据库插入数据,负责显示
建表语句
create table list(
id int not null auto_increment primary key,
listname varchar(20) not null default '',
listpsw varchar(20) not null
)engine myisam charset utf8;
listdemo.html
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>Document</title>
</head>
<body>
<form action='../list.php' method='post'>
用户名:<input type='text' name='listname'/><br/>
密码:<input type='password' name='listpsw'/><br/>
<input type='submit' value='提交'/>
</from>
</body>
</html>
listmodel.class.php
<?php
class Model{
protected $table=null;//是model所控制的表
protected $db=null;//是引入的类 public function __construct(){
$this->db=mysql::getIns();
}
public function table($table){
$this->table=$table;
}
}
?>
list.php
<?php
define('ACC',true);
include('./include/init.php'); $data=$_POST; $list=new listModel();
print_r($data);
$res=$list->reg($data);
if($res){
echo '添加成功';
}else{
echo '添加失败';
}
?>