Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I found where was the error.</p> <pre><code>if ($query-&gt;num_rows() == 1) </code></pre> <p>is not the correct syntax</p> <pre><code>if ($query-&gt;num_rows == 1) </code></pre> <p>is the correct one. $query->num_rows value is "1"</p> <p>finally the solution i choose is : </p> <p>my user_model.php (for database operation with users )</p> <pre><code>class Users_model extends MY_Model { protected $table = 'users'; protected $primary = 'user_id'; public function liste() { $this-&gt;link-&gt;select('user_id'); $this-&gt;link-&gt;select('user_name'); $this-&gt;link-&gt;select('user_mail'); $this-&gt;link-&gt;select("GROUP_CONCAT(group_name ORDER BY group_name SEPARATOR '&lt;br /&gt;') AS user_groups", FALSE); $this-&gt;link-&gt;join('groups_users', 'users_user_id=user_id', 'left'); $this-&gt;link-&gt;join('groups', 'group_id=groups_group_id', 'left'); $this-&gt;link-&gt;group_by('user_id'); return parent::get_all(array(), array('user_name ASC')); } public function validate($mail, $password) { $pass_hashed = sha1($mail . $password); return parent::get(array('user_mail' =&gt; $mail, 'user_password' =&gt; $pass_hashed)); } } /* End of file users_model.php */ /* Location: ./application/models/users_model.php */ </code></pre> <p>The validate method is more simple, and i dont do any controls in it. Just Db operations.</p> <p>Now my controller accueil.php</p> <pre><code>&lt;?php if (!defined('BASEPATH')) exit('No direct script access allowed'); class Accueil extends MY_Controller { public function __construct() { parent::__construct(); $this-&gt;load-&gt;model('users_model', 'users_m'); // Chargement model $this-&gt;load-&gt;library('form_validation'); // Librairie validation $this-&gt;load-&gt;helper(array('form', 'url')); // helpers $this-&gt;load-&gt;library('template'); // Librairie template } public function index($msg = NULL) //msg en cas d'erreur , NULL si pas d'erreur { $data['msg'] = $msg; $this-&gt;load-&gt;view('login', $data); } public function login() { try { $user = $this-&gt;users_m-&gt;validate($this-&gt;input-&gt;post('user_mail'), $this-&gt;input-&gt;post('password')); $this-&gt;session-&gt;set_userdata(array( 'user_id' =&gt; $user-&gt;user_id, 'user_mail' =&gt; $user-&gt;user_mail, 'validated' =&gt; TRUE )); redirect('users'); } catch (Exception $e) { // Pas de validation on renvoit vers l'index avec un message d'erreur $msg = '&lt;font color=red&gt;Nom d\'utilisateur ou mot de passe incorrect(s).&lt;/font&gt;&lt;br /&gt;'; $this-&gt;index($msg); } } } /* End of file accueil.php */ /* Location: ./application/controllers/accueil.php */ </code></pre> <p>My view is still the same , no changes.</p> <p>I think i have wrote the code more correctly this time. </p> <p>Separate the DB operations , with the controls.</p> <p>Feel free to comments.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload