
class IndexAction extends Action {
public function index(){
$this->display("index2");
}
public function show(){
if(empty($_POST))
{
echo iconv("utf-8","gb2312","页面不存在");
header("refresh:2;url=".u("index"));
}
else
{
//原生PHP插入
$conn=mysql_connect("localhost","root","");
mysql_select_db("think_post",$conn);
mysql_query("set names gb2312",$conn);
mysql_query("insert into `think_user`(`id`,`nicheng`,`liuyan`) values('','{$_POST['nicheng']}','{$_POST['liuyan']}')",$conn)or die(mysql_error());
//thinkphp框架插入
$arr1=array("nicheng"=>i('nicheng'),"liuyan"=>i('liuyan'));
$arr=array();
foreach($arr1 as $key=>$val)
{
$arr[]=iconv("gb2312","utf-8",$val);
}
m("user")->data($arr)->add();
}
}
}
/*
//这是创建数据库的sql代码
$conn=mysql_connect("localhost","root","");
mysql_query("set names gb2312",$conn)or die(mysql_error()."创建字体失败");
if(!mysql_select_db("think_post",$conn))
{
mysql_query("create databa
mysql_select_db("think_post",$conn);
mysql_query("create table `think_user`(`id` int(2) unsigned not null auto_increment primary key,`nicheng` char(20) character set utf8 collate utf8_unicode_ci not null,`liuyan` char(30) character set utf8 collate utf8_unicode_ci not null)")or die(mysql_error()."创建表失败");
}
*/
最佳答案