Question

I have the 1054 error in Codeigniter and I don't know why. I want to create a login form and check if the user is logged or not.

But I only create a simple view and controller and the following error is displayed:

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

I only created the table session with this script:

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)
);

The view:

<!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>

The controller:

<?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";
}


 }
?>  

How can I fix this issue?

Thanks.

Was it helpful?

Solution

The manual states your ci_sessions table should be created like this:

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`)
);

Note the "user_data" field that's missing from your table.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top