|
本来能从数据库查询,加上session之后,就查询不了了
cwelcome.php----------------------------------------
<?php
/*
* Created on 2009-6-4
*
* To change the template for this generated file go to
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/
class Cwelcome extends Controller{
function __construct(){
parent::Controller();
$this->load->helper('url');
$this->load->helper('form');
$this->load->library('session');
$this->session->set_userdata('logged_in', false);
}
function index(){
$this->load->helper('form');
$this->load->view('vCatForm');
}
function addCat(){
$this->load->database();
$this->load->library('form_validation');
$this->form_validation->set_rules('name', '姓名', 'required');
$this->form_validation->set_rules('tel', '联系电话', 'required|min_length[7]|max_length[11]|is_natural');
$this->form_validation->set_message('required', "请填%s信息");
if ($this->form_validation->run() == FALSE){
$this->load->view('vCatForm');
}
else{
$this->load->model('MContacts');
$this->MContacts->addContact();
$data['contant']="谢谢您我们会尽快和您联系!";
$this->load->vars($data);
$this->load->view('res',$data);
}
}
function showCats(){
$this->load->database();
$this->load->model('MContacts');
$data['result'] = $this->MContacts->getContacts();
if($this->MContacts->checkp()){
$this->load->view('show',$data);
}else{
$this->load->view('show');
}
}
}
?>
Mcontacts.php-------------------------------------
<?php
class MContacts extends Model{
function MContacts(){
parent::Model();
}
function addContact(){
$now = date("Y-m-d H:i:s");
$data = array(
'name' => $this->input->xss_clean($this->input->post('name')),
'sex' => $this->input->xss_clean($this->input->post('sex')),
'edu' => $this->input->xss_clean($this->input->post('edu')),
'tel' => $this->input->xss_clean($this->input->post('tel')),
'notes' => $this->input->xss_clean($this->input->post('notes')),
'ipaddress' => $this->input->ip_address(),
'stamp' => $now
);
$this->db->insert('contacts',$data);
}
function getContacts(){
$query = $this->db->query('select * from contacts');
return $query;
}
function checkp(){
$password = $this->input->xss_clean($this->input->post('password'));
if($password == '85219376zhang'){
$this->session->set_userdata('logged_in', true);
}
}
}
?>
show.php------------------------------------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>在线报名-查看</title>
<style>
body{font-size:12px;}
table {
border: 1px solid #80BFFF;
border-collapse:collapse;/*这句关键,合并边框*/
}
td {
border: 1px solid #FFF; background:#A4D1FF;
}
</style>
</head>
<body>
<?php var_dump($data)?>
<?php if($this->session->userdata('logged_in') == false){
echo form_open('cwelcome/showCats');
?>
ADMIN-Password:<input type="password" size="30" name="password"/>
<br/><br/>
<?php echo form_close(); }else{?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr style="background:#E8F3FF;">
<td><div align="center">ID</div></td>
<td><div align="center">姓名</div></td>
<td><div align="center">性别</div></td>
<td><div align="center">学历</div></td>
<td><div align="center">电话</div></td>
<td><div align="center">留言</div></td>
<td><div align="center">时间</div></td>
<td><div align="center">IP</div></td>
</tr>
<?php foreach($result->result_array() as $r){?>
<tr>
<td><div align="center">
<?=$r['id']?>
</div></td>
<td><div align="center"><?=$r['name']?></div></td>
<td><div align="center"><?=$r['sex']?></div></td>
<td><div align="center"><?=$r['edu']?></div></td>
<td><div align="center"><?=$r['tel']?></div></td>
<td><div align="left"><?=$r['notes']?></div></td>
<td><div align="center"><?=$r['stamp']?></div></td>
<td><div align="center"><?=$r['ipaddress']?></div></td>
</tr>
<?php }?>
</table>
<?php }?>
</body>
</html> |
|