Welcome Guest, Not a member yet? Register   Sign In
Session data disappears using a unicode text in set_flashdata message
#1

[eluser]afshin[/eluser]
Hi, I am a brand new codeigniter programmer.
I'm getting an error using a unicode(persian) message text with set_flashdata . When the message is in English, I get no errors.



Code:
$this->session->set_flashdata('message', 'بروز گردید');
redirect(current_url());




The error I'm getting :


Quote:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

SELECT userFirstname FROM mavi_users WHERE userId=;

Filename: D:\xampp\htdocs\parastooha\system\database\DB_driver.php

Line Number: 330


It says that userId= '' . But, of course the code I am using in a view file is this :


Code:
<?php
$userId = $this->session->userdata('userId');
$query = $this->db->query('SELECT userFirstname FROM mavi_users WHERE userId='.$userId.';');
$userFirstname = $query->row('userFirstname');
echo 'Welcome, '.$userFirstname;
?>



This is my controller :

Code:
<?php

class Students extends CI_Controller {
    
    function __consttuct()
    {
        parent::__construct();
        if (!$this->session->userdata('userId'))
        {
            redirect('admin/dashboard/login');
        }
    }
    
    
         /**
     *
     *  Checks if the admin user is logged in or not.
     *
     */
    
    function is_logged_in()
{
  if ($this->session->userdata('userId'))
  {
   return TRUE;
  }
  else
  {
   return FALSE;
  }
}
    
    //Retrieve students
    
    function index()
    {  
            if($this->is_logged_in())
            {
                $this->load->model('admin/students_model');
                $data = array();
                if($query = $this->students_model->get_students())
                {
                    $data['students'] = $query;
                }
                
                $data['main_content'] = 'admin/students_list';
                $this->load->view('admin/includes/template', $data);
            }
            else
            {
                redirect('admin/dashboard/login');
            }      
    }
    
    //Register students
    
     function register()
     {
        $this->form_validation->set_rules('studentIdnum', 'Student ID', 'trim|required');
        $this->form_validation->set_rules('studentPassword', 'Password', 'trim|min_length[4]|max_length[10]');
        $this->form_validation->set_message('valid_email', ' %s is not a valid email.');
        $this->form_validation->set_error_delimiters('<li>', '</li>');
        
        if($this->form_validation->run())
        {
            $this->load->model('admin/students_model');
            $studentId = $this->students_model->register_student($_POST);
            
            if($studentId)
            {
                $this->session->set_flashdata('message', 'بروز گردید');
                redirect(current_url());
            }
            else
            {
                redirect ('admin/students/register');
            }
        }
        
        $data['main_content'] = 'admin/student_register';
        $this->load->view('admin/includes/template', $data);
     }
        
}
?&gt;





This is the Session Variables in config part :


Code:
$config['sess_cookie_name']  = 'mavi_session';
$config['sess_expiration']  = 7200;
$config['sess_expire_on_close'] = FALSE;
$config['sess_encrypt_cookie'] = TRUE;
$config['sess_use_database'] = TRUE;
$config['sess_table_name']  = 'mavi_sessions';
$config['sess_match_ip']  = TRUE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update'] = 300;




and also the Encryption Key :


Code:
$config['encryption_key'] = 'xMAN3ZzZ59s1B1Vy6CZGfmqCj3vP25sT';


What should I do so?!




Theme © iAndrew 2016 - Forum software by © MyBB