Welcome Guest, Not a member yet? Register   Sign In
[help]School Project Here
#1

[eluser]miwrath[/eluser]
Hello im Mark, im a computer science student...

i need help for the first Codeigniter project that i have to do...
its a school project for my thesis...
this is my first time to use CI.

i made this thread to easy help me for my codings...

i hope this section is the right one on this topic...
#2

[eluser]miwrath[/eluser]
i have my first problem here:

Quote:A Database Error Occurred

Error Number: 1054

Unknown column 'session_id' in 'where clause'

SELECT * FROM (`users`) WHERE `session_id` = '36dcbcb4a57fca10dccaff1dd686c5fe' AND `user_agent` = 'Mozilla/5.0 (Windows NT 5.1; rv:2.0.1) Gecko/20100'

i set my database by this message still cames out...

need help pls... Sad
#3

[eluser]Bart v B[/eluser]
Did you load the session class?
Did you try it direct in the database?
#4

[eluser]davidbehler[/eluser]
This simply means there's no column called session_id in your users table.
You should set up your sessins table like described in the User Guide and fix your settings, apparently you've set the name of your session table to 'users'.

Update config/config.php and change the value for '$config['sess_table_name']' to 'ci_sessions'.
#5

[eluser]miwrath[/eluser]
so it means...i have to create 'session_id' in my 'users' table in database?

and put it back again the 'ci_sessions' in ‘$config[‘sess_table_name’]’????
#6

[eluser]davidbehler[/eluser]
Why is your sessions table called 'users'? Users are not the same as sessions.
#7

[eluser]miwrath[/eluser]
i got it sir..."users" is my table name...
here is my next problem...

hoooooooooo...this is going to be tough...

thank you so much Mr.waldmeister for your help...

Quote:A PHP Error was encountered

Severity: Notice

Message: Undefined variable: password

Filename: models/user_model.php

Line Number: 11
A PHP Error was encountered

Severity: Notice

Message: Undefined variable: username

Filename: models/user_model.php

Line Number: 13
A PHP Error was encountered

Severity: Notice

Message: Undefined variable: password

Filename: models/user_model.php

Line Number: 13
A PHP Error was encountered

Severity: Notice

Message: Undefined variable: username

Filename: models/user_model.php

Line Number: 15
A Database Error Occurred

Error Number: 1054

Unknown column 'user_data' in 'field list'

UPDATE `users` SET `last_activity` = '1313642093', `user_data` = 'a:2:{s:9:\"logged_in\";s:1:\"1\";s:8:\"teach_id\";s:1:\"4\";}' WHERE `session_id` = '91f87c3b4afad66994323f967992df10'
#8

[eluser]davidbehler[/eluser]
I'll keep repeating myself till you get it right : Just use the table definition that's provided in the User Guide instead of manually adding every column the session library needs to your users table.

Those 'undefined variable: .." errors mean you are trying to access a variable that does not exist (yet). But without seeing some of your code it's pretty hard to tell what's going wrong.

Have you ever coded with PHP before? It's essential that you know PHP if you want to use CI! It's just a framework that makes it easier to set up and build your projects, but it doesn't remove the need of knowing how to code in the first place!
#9

[eluser]miwrath[/eluser]
im so sorry Mr. waldmeister im just beginning my journey to learn deeply the PHP...
im just a self study kid...
huhuhu


user_model.php in my models folder.
Code:
<?php
class User_model extends Model {
    
    function User_model()
    {
        parent::Model();
    }
    
    function check_login()
    {
        $shal_password = sha1($password);
        
        $query_str = "SELECT * FROM users WHERE username = '$username' and password = '$password'";
        
        $result = $this->db->query($query_str, array($username, $shal_password));
        
        if ($result->num_rows() == 1)
        {
            return $result->row(0)->teach_id;
        }
        else
        {
            return false;
        }
        
    }
    
    
    
}


?>


view file "view_registrar" in my views folder.
Code:
<html>
<head>
<title>Welcome</title>

</head>
<body>

<div id="login_form">
    <h1>Please login.</h1>
    <p>Use the form to login...</p>
    
&lt;?php echo form_open(base_url() . 'index.php/registrar/login'); ?&gt;  
    
    <ul>
    <li>
        <label>Username</label>
        <div>
            &lt;?php echo form_input(array ('id'=> 'username', 'name'=> 'username'));?&gt;        
        </div>
    </li>
    <li>
                <label>Password</label>
        <div>
            &lt;?php echo form_password(array ('id'=> 'password', 'name'=> 'password'));?&gt;        
        </div>    
    </li>
        
    <li>
        &lt;?php
            if ($this->session->flashdata('login_error'))
            {
                echo 'You entered incorrect username or password';
            }
            
            echo validation_errors(); ?&gt;</li>
    
        &lt;?php echo form_submit(array('name' => 'submit'), 'Login'); ?&gt;
        
    </ul>

&lt;?php echo form_close(); ?&gt;
    
</div>


&lt;/body&gt;
&lt;/html&gt;


hope this will clear up things...
#10

[eluser]davidbehler[/eluser]
Don't call me Mr...I'm not that old Wink Nothing bad about teaching this stuff yourself, but maybe you should start with something straight forward..some tutorials on plain functional php and once you mastered those you can continue to OOP and using frameworks like CI.

But anyway, let's fix your problems:

Change your function defintion slightly:
Code:
function check_login($username, $password)
and you gotta decide which way you want to go when running your queries.

Either fully build your query string and then run it:
Code:
$query_str = "SELECT * FROM users WHERE username = '$username' and password = '$password'";
        
$result = $this->db->query($query_str);
or use query bindings:
Code:
$query_str = "SELECT * FROM users WHERE username = ? and password = ?";
        
$result = $this->db->query($query_str, array($username, $shal_password));
or use active record:
Code:
$this->db->where('username', $username);
$this->db->where('password', $password);
$result = $this->db->get('users');




Theme © iAndrew 2016 - Forum software by © MyBB