用户
 找回密码
 入住 CI 中国社区
搜索
查看: 2362|回复: 3
收起左侧

不知道是哪里出错了

[复制链接]
发表于 2009-6-5 12:24:26 | 显示全部楼层 |阅读模式
本来能从数据库查询,加上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>
发表于 2009-6-5 12:35:52 | 显示全部楼层
囧,是哪个步骤不能查询?之前之后的症状能发一下吗?
lz可以试试逐个method用var_dump()调式session和result
发表于 2009-6-5 12:36:42 | 显示全部楼层
报什么错误呢?有什么异常呢?
发表于 2009-8-28 10:20:39 | 显示全部楼层
看这个帖子不错,至少知道基础的写法~呵呵~问题解决了吗?说说呗

本版积分规则