0

我在 Codeigniter 中有 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";
}


 }
?>  

我该如何解决这个问题?

谢谢。

4

1 回答 1

2

手册指出您的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”字段。

于 2013-05-08T12:14:16.490 回答