2013-05-08 121 views
0

我在Codeigniter中有1054错误,我不知道为什么。我想创建一个登录表单并检查用户是否登录。Codeigniter 2.1.3中的错误1054

但我只创建一个简单的视图和控制器以及以下错误显示:

Error Number: 1054 

Unknown column 'user_data' in 'field list' 

INSERT INTO `ci_sessions` (`session_id`, `ip_address`, `user_agent`, `last_activity`, `user_data`) VALUES ('c392322ac31b7fac1c2d79cfbde9edf7', '127.0.0.1', 'Opera/9.80 (Windows NT 6.1) Presto/2.12.388 Version/12.15', 1368010716, '') 

Filename: C:\wamp\www\..\system\database\DB_driver.php 

Line Number: 330 

我只创建了这个脚本的表会话:

CREATE TABLE IF NOT EXISTS `ci_sessions` (
session_id varchar(40) DEFAULT '0' NOT NULL, 
ip_address varchar(45) DEFAULT '0' NOT NULL, 
user_agent varchar(50) NOT NULL, 
last_activity int(10) unsigned DEFAULT 0 NOT NULL, 
PRIMARY KEY (session_id) 
); 

的观点:

<!DOCTYPE html> 
<html lang="en"> 
<head> 
<meta charset="utf-8"> 
<title>Anuncios</title> 
<link rel="stylesheet" href="/Pruebas/css/estilos.css" type="text/css" 
    media="screen"/>  
</head> 

<body> 

<div id="contenedor"> 
<div id="menu"> 
    <label for="home" id="inicio"><a href="http://localhost/Pruebas/index.php/ 
cindice/">Inicio</a></label> 
    <label for="acceso" id="login"><a href="http://localhost/Pruebas/index.php/ 
cindice/publicar">Publicar anuncio</a></label> 
    <label for="reg" id="registro"><a href="http://localhost/Pruebas/index.php/ 
cindice/registro">Registro</a></label> 
    <label for="empresa" id="sobrempresa"><a href="http://localhost/Pruebas/ 
index.php/cindice/sobempresa">Sobre nosotros</a></label> 
    <label for="contacto" id="contactar"><a href="http://localhost/Pruebas/ 
index.php/cindice/contacto">Cont&aacute;ctanos</a></label> 
</div> 
</div> 

</body> 
</html> 

控制器:

<?php if (! defined('BASEPATH')) exit('No direct script access allowed'); 


class Cindice extends CI_Controller { 

function __construct() { 
    parent::__construct(); 
} 

public function index() 
{ 
    $this->load->view('indice'); 
} 

public function publicar() 
{ 
    echo "Aqu&iacute; se publica el anuncio"; 
} 

public function acceso() 
{ 
    echo "Esto es el acceso"; 
} 


} 
?> 

我该如何解决这个问题?

谢谢。

回答

2

manual指出你的ci_sessions表应该像这样创建:

CREATE TABLE IF NOT EXISTS `ci_sessions` (
session_id varchar(40) DEFAULT '0' NOT NULL, 
ip_address varchar(45) DEFAULT '0' NOT NULL, 
user_agent varchar(120) NOT NULL, 
last_activity int(10) unsigned DEFAULT 0 NOT NULL, 
user_data text NOT NULL, 
PRIMARY KEY (session_id), 
KEY `last_activity_idx` (`last_activity`) 
); 

注意“USER_DATA”字段,其从表中失踪。

+0

它的工作原理,谢谢。 – axmug 2013-05-09 07:48:21