[eluser]CI-Newb[/eluser]
Hello, I've added the following to "My_Form_validation.php" to allow 'updates' with unique values:
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class My_Form_validation extends CI_Form_validation {
public function is_unique($str, $field)
{
list($table, $field)=explode('.', $field);
$q = $this->CI->db->query("SHOW KEYS FROM $table WHERE Key_name = 'PRIMARY'")->row();
$primary_key = $q->Column_name;
if($this->CI->input->post($primary_key) > 0):
$query = $this->CI->db->limit(1)->get_where($table, array($field => $str,$primary_key.' !='=>$this->CI->input->post($primary_key)));
else:
$query = $this->CI->db->limit(1)->get_where($table, array($field => $str));
endif;
return $query->num_rows() === 0;
}
}
/* End of file My_Form_validation.php */
/* Location: ./application/libraries/My_Form_validation.php */
This works perfectly on my localhost environment. When I upload it to the live server it does not function. When I enable the profiler I can see that it actually isn't working, (see below)
Code:
Localhost:
0.0005 SHOW KEYS FROM users WHERE Key_name = 'PRIMARY'
0.0003 SELECT *
FROM (`users`)
WHERE `username` = 'mike'
AND `id` != '1'
LIMIT 1
LiveServer:(same code)
0.0001 SELECT *
FROM (`users`)
WHERE `username` = 'mike'
LIMIT 1
Would anyone happen to have any idea's why this could be happening and how to fix it? Why will this not load?