اذهب إلى المحتوى

السؤال

نشر

لدى اسكريبت للاعلانات و بة اضافة تسجيل الدخول عن طريق الفيس , قمت بأنشاء التطبيق و ربطة بالاسكريبت و لكن عند تسجيل الدخول من الفيسبوك  يعطى هذا الخطأ  

Error Number: 1048

Column 'first_name' cannot be null

INSERT INTO `dbc_users` (`user_type`, `first_name`, `last_name`, `gender`, `user_name`, `profile_photo`, `user_email`, `password`, `confirmed`, `status`) VALUES (3, NULL, NULL, NULL, 'fb_user1', 'fb_user1.jpg', NULL, '', 1, 1)

Filename: /home/passw00rd/public_html/modules/account/models/auth_model_core.php

Line Number: 218 

ما هو الحل من فضلكم 

Recommended Posts

  • 1
نشر

حسب رسالة الخطأ فإنّ قيمة الحقل first_name هي NULL، وهذا هو سبب الخطأ:

Column 'first_name' cannot be null

تخبرك الرسالة السابقة أنّه لا يمكن للحقل first_name أن يكون null. حدثت هذه المشكلة ضمن الملف auth_model_core.php. أنصحك أن تجرّب وضع قيم فعلية بدلًا من NULL، وذلك مكان كل من first_name و last_name و gender. ثم جرّب مرّة أخرى.

  • 0
نشر
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * Classified auth model
 *
 * This class handles user account related functionality
 *
 * @package		Account
 * @subpackage	models/auth
 * @author		dbcinfotech
 * @link		http://dbcinfotech.net
 */


class Auth_model_core extends CI_Model 
{
	function __construct()
	{
		parent::__construct();
		$this->load->database();
	}
	
	function check_login($user_email,$password,$return_as='num_rows')
	{
		$this->load->library('encrypt');
		$password = $this->encrypt->sha1($password);
		$this->db->where('user_email',$user_email);
		$query = $this->db->get_where('users',array('password'=>$password));
		if($return_as=='num_rows')
		return $query->num_rows();
		else
		return $query;
	}

	function set_login_cookie($user_email)
	{
		$val = rand(1000,9000);
		$cookie = array(
                   'name'   => 'key',
                   'value'  => $val,
                   'expire' => '86500',
                   'domain' => '.localhost',
                   'path'   => '/',
                   'prefix' => 'mycookie_',
               );

		set_cookie($cookie);
		
		$cookie = array(
                   'name'   => 'user',
                   'value'  => $user_email,
                   'expire' => '86500',
                   'domain' => '.localhost',
                   'path'   => '/',
                   'prefix' => 'mycookie_',
               );

		set_cookie($cookie);
		
		$data['remember_me_key'] = $val;
		$this->db->update('users',$data,array('user_email'=>$user_email));
	}
	
	function check_cookie_val($user,$key)
	{
		$query = $this->db->get_where('users',array('user_email'=>$user,'remember_me_key'=>$key));
		if($query->num_rows()>0)
		{
			$this->session->set_userdata('user_email',$user);
		}
	}
	
	function is_email_exists($email)
	{
		$query = $this->db->get_where('users',array('user_email'=>$email));
		return $query->num_rows();
	}

	function is_username_exists($user_name)
	{
		$query = $this->db->get_where('users',array('user_name'=>$user_name));
		return $query->num_rows();
	}

	function is_email_exists_for_edit($email,$id)
	{
		$query = $this->db->get_where('users',array('user_email'=>$email,'id !='=>$id));
		return $query->num_rows();
	}

	function is_username_exists_for_edit($user_name,$id)
	{
		$query = $this->db->get_where('users',array('user_name'=>$user_name,'id !='=>$id));
		return $query->num_rows();
	}

	
	function set_recovery_key($user_email)
	{
		$recovery_key = uniqid();
		$this->db->update('users',array('recovery_key'=>$recovery_key),array('user_email'=>$user_email));
		
		$query = $this->db->get_where('users',array('user_email'=>$user_email));
		$data = $query->row_array();
		$data['recovery_key'] = $recovery_key;
		//echo '<pre>';print_r($data);die;
		return $data;
	}

	function verify_recovery_by_username($user_name,$recovery_key)
	{
		if($user_name=='' || $recovery_key=='')
			return 0;
		else
		{
			$query = $this->db->get_where('users',array('user_name'=>$user_name,'recovery_key'=>$recovery_key));
			return $query;
		}
	}

	function verify_recovery($user_email,$recovery_key)
	{
		if($user_email=='' || $recovery_key=='')
			return 0;
		else
		{
			$query = $this->db->get_where('users',array('user_email'=>$user_email,'recovery_key'=>$recovery_key));
			return $query;
		}
	}
	
	function get_userdata_by_email($email)
	{
		$query = $this->db->get_where('users',array('user_email'=>$email));
		return $query->row_array();
	}

	function confirm_email($email,$code)
	{
		$query = $this->db->get_where('users',array('user_email'=>$email,'confirmation_key'=>$code));
		if($query->num_rows()>0)
		{
			$this->load->helper('date');
			$datestring = "%Y-%m-%d %h:%i:00";
			$time = time();

			$data['confirmed'] = 1;
			$data['confirmed_date'] = mdate($datestring, $time);
			$data['confirmation_key'] = '';
			$this->db->update('users',$data,array('user_email'=>$email));
			return TRUE;
		}
		else
		{
			return FALSE;
		}
	}

	function register_user_if_not_exists($user,$network='')
	{
		$query = $this->db->get_where('users',array('user_email'=>$user['email']));
		if($query->num_rows()>0)
		{
			$row = $query->row_array();
			return $row;
		}
		else
		{
			$userdata 				= array();
			$userdata['user_type']	= ($this->session->userdata('signup_user_type')!='')?$this->session->userdata('signup_user_type'):2;//2 = users
			$userdata['first_name'] = $user['first_name'];
			$userdata['last_name'] 	= $user['last_name'];
			$userdata['gender'] 	= $user['gender'];
			if($network=='google')
			{
				if($user['username']=='')
				{
					$this->db->like('user_name','gp_');
					$query = $this->db->get_where('users');
					$total = $query->num_rows();
					$tmp_username = 'gp_user'.($total+1);
				}
				else
				{
					$tmp_username = 'gp_'.$user['username'];				
				}

				$userdata['user_name'] 	= $tmp_username;
			}
			else
			{
				if($user['username']=='')
				{
					$this->db->like('user_name','fb_');
					$query = $this->db->get_where('users');
					$total = $query->num_rows();
					$tmp_username = 'fb_user'.($total+1);
				}
				else
				{
					$tmp_username = 'fb_'.$user['username'];				
				}

				$userdata['user_name'] 	= $tmp_username;

				$img = @file_get_contents('http://graph.facebook.com/'.$user['id'].'/picture?type=large');
				$file = './uploads/profile_photos/'.$tmp_username.'.jpg';
				file_put_contents($file, $img);
				create_square_thumb('./uploads/profile_photos/'.$tmp_username.'.jpg','./uploads/profile_photos/');
				$file = './uploads/profile_photos/thumb/'.$tmp_username.'.jpg';
				file_put_contents($file, $img);
				create_square_thumb('./uploads/profile_photos/thumb/'.$tmp_username.'.jpg','./uploads/profile_photos/thumb/');
				$userdata['profile_photo'] =  ''.$tmp_username.'.jpg';
			}
			$userdata['user_email'] = $user['email'];
			$userdata['password'] 	= '';
			$userdata['confirmed'] 	= 1;
			$userdata['status']		= 1;
			$this->db->insert('dbc_users',$userdata);
			$userdata['id']			= $this->db->insert_id();
			return $userdata;		
		}
	}
}

/* End of file auth_model.php */
/* Location: ./system/application/modules/account/models/auth_model.php */

هذا هو الكود الذى به الخطأ هل يمكنك تعديه لأني لا أعرف لغة php 

  • 1
نشر

لقد أجريت تعديلًا بسيطًا على هذا السكريبت، حيث أدخلت اسم المستخدم بشكل ثابت. نفذ السكريبت وأخبرني بالنتائج:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * Classified auth model
 *
 * This class handles user account related functionality
 *
 * @package		Account
 * @subpackage	models/auth
 * @author		dbcinfotech
 * @link		http://dbcinfotech.net
 */


class Auth_model_core extends CI_Model 
{
	function __construct()
	{
		parent::__construct();
		$this->load->database();
	}
	
	function check_login($user_email,$password,$return_as='num_rows')
	{
		$this->load->library('encrypt');
		$password = $this->encrypt->sha1($password);
		$this->db->where('user_email',$user_email);
		$query = $this->db->get_where('users',array('password'=>$password));
		if($return_as=='num_rows')
		return $query->num_rows();
		else
		return $query;
	}

	function set_login_cookie($user_email)
	{
		$val = rand(1000,9000);
		$cookie = array(
                   'name'   => 'key',
                   'value'  => $val,
                   'expire' => '86500',
                   'domain' => '.localhost',
                   'path'   => '/',
                   'prefix' => 'mycookie_',
               );

		set_cookie($cookie);
		
		$cookie = array(
                   'name'   => 'user',
                   'value'  => $user_email,
                   'expire' => '86500',
                   'domain' => '.localhost',
                   'path'   => '/',
                   'prefix' => 'mycookie_',
               );

		set_cookie($cookie);
		
		$data['remember_me_key'] = $val;
		$this->db->update('users',$data,array('user_email'=>$user_email));
	}
	
	function check_cookie_val($user,$key)
	{
		$query = $this->db->get_where('users',array('user_email'=>$user,'remember_me_key'=>$key));
		if($query->num_rows()>0)
		{
			$this->session->set_userdata('user_email',$user);
		}
	}
	
	function is_email_exists($email)
	{
		$query = $this->db->get_where('users',array('user_email'=>$email));
		return $query->num_rows();
	}

	function is_username_exists($user_name)
	{
		$query = $this->db->get_where('users',array('user_name'=>$user_name));
		return $query->num_rows();
	}

	function is_email_exists_for_edit($email,$id)
	{
		$query = $this->db->get_where('users',array('user_email'=>$email,'id !='=>$id));
		return $query->num_rows();
	}

	function is_username_exists_for_edit($user_name,$id)
	{
		$query = $this->db->get_where('users',array('user_name'=>$user_name,'id !='=>$id));
		return $query->num_rows();
	}

	
	function set_recovery_key($user_email)
	{
		$recovery_key = uniqid();
		$this->db->update('users',array('recovery_key'=>$recovery_key),array('user_email'=>$user_email));
		
		$query = $this->db->get_where('users',array('user_email'=>$user_email));
		$data = $query->row_array();
		$data['recovery_key'] = $recovery_key;
		//echo '<pre>';print_r($data);die;
		return $data;
	}

	function verify_recovery_by_username($user_name,$recovery_key)
	{
		if($user_name=='' || $recovery_key=='')
			return 0;
		else
		{
			$query = $this->db->get_where('users',array('user_name'=>$user_name,'recovery_key'=>$recovery_key));
			return $query;
		}
	}

	function verify_recovery($user_email,$recovery_key)
	{
		if($user_email=='' || $recovery_key=='')
			return 0;
		else
		{
			$query = $this->db->get_where('users',array('user_email'=>$user_email,'recovery_key'=>$recovery_key));
			return $query;
		}
	}
	
	function get_userdata_by_email($email)
	{
		$query = $this->db->get_where('users',array('user_email'=>$email));
		return $query->row_array();
	}

	function confirm_email($email,$code)
	{
		$query = $this->db->get_where('users',array('user_email'=>$email,'confirmation_key'=>$code));
		if($query->num_rows()>0)
		{
			$this->load->helper('date');
			$datestring = "%Y-%m-%d %h:%i:00";
			$time = time();

			$data['confirmed'] = 1;
			$data['confirmed_date'] = mdate($datestring, $time);
			$data['confirmation_key'] = '';
			$this->db->update('users',$data,array('user_email'=>$email));
			return TRUE;
		}
		else
		{
			return FALSE;
		}
	}

	function register_user_if_not_exists($user,$network='')
	{
		$query = $this->db->get_where('users',array('user_email'=>$user['email']));
		if($query->num_rows()>0)
		{
			$row = $query->row_array();
			return $row;
		}
		else
		{
			$userdata 				= array();
			$userdata['user_type']	= ($this->session->userdata('signup_user_type')!='')?$this->session->userdata('signup_user_type'):2;//2 = users
			$userdata['first_name'] = $user['first_name'];
			$userdata['last_name'] 	= $user['last_name'];
			$userdata['gender'] 	= $user['gender'];
			if($network=='google')
			{
				if($user['username']=='')
				{
					$this->db->like('user_name','gp_');
					$query = $this->db->get_where('users');
					$total = $query->num_rows();
					$tmp_username = 'gp_user'.($total+1);
				}
				else
				{
					$tmp_username = 'gp_'.$user['username'];				
				}

				$userdata['user_name'] 	= 'gp_tmpuser';
			}
			else
			{
				if($user['username']=='')
				{
					$this->db->like('user_name','fb_');
					$query = $this->db->get_where('users');
					$total = $query->num_rows();
					$tmp_username = 'fb_user'.($total+1);
				}
				else
				{
					$tmp_username = 'fb_'.$user['username'];				
				}

				$userdata['user_name'] 	= 'fb_tmpuser';

				$img = @file_get_contents('http://graph.facebook.com/'.$user['id'].'/picture?type=large');
				$file = './uploads/profile_photos/'.$tmp_username.'.jpg';
				file_put_contents($file, $img);
				create_square_thumb('./uploads/profile_photos/'.$tmp_username.'.jpg','./uploads/profile_photos/');
				$file = './uploads/profile_photos/thumb/'.$tmp_username.'.jpg';
				file_put_contents($file, $img);
				create_square_thumb('./uploads/profile_photos/thumb/'.$tmp_username.'.jpg','./uploads/profile_photos/thumb/');
				$userdata['profile_photo'] =  ''.$tmp_username.'.jpg';
			}
			$userdata['user_email'] = $user['email'];
			$userdata['password'] 	= '';
			$userdata['confirmed'] 	= 1;
			$userdata['status']		= 1;
			$this->db->insert('dbc_users',$userdata);
			$userdata['id']			= $this->db->insert_id();
			return $userdata;		
		}
	}
}

 

انضم إلى النقاش

يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.

زائر
أجب على هذا السؤال...

×   لقد أضفت محتوى بخط أو تنسيق مختلف.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   جرى استعادة المحتوى السابق..   امسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

  • إعلانات

  • تابعنا على



×
×
  • أضف...