Codeigniter User Session Error - php

I'm face a new Problem in Codeigniter Framework. Her is my Out put
Array
(
[id] => 2
[firstname] => Maruf
[lastname] => Ifftekhar
[slug] =>
[email] => support#russelhost.com
[email_subscribe] => 1
[self] =>
[phone] => 01767820010
[company] => Russel Host
[default_billing_address] =>
[default_shipping_address] =>
[ship_to_bill_address] => true
[password] => 0689d59aa30bdca7207db3d449255650
[active] => 1
[group_id] => 1
[confirmed] => 0
[group_discount_formula] => - 0
[expire] => 1380390903
)
A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: controllers/secure.php
Line Number: 46
abida Sultana
Here is Controller
`$`email = `$`this->input->post('email');
`$`password = `$`this->input->post('password');
`$`remember = `$`this->input->post('remember');
`$`redirect = `$`this->input->post('redirect');
`$`login = `$`this->Customer_model->login(`$`email, `$`password, `$`remember);
echo '/pre>-----';
print_r(`$`login);
echo 'abida Sultana'.`$`login->last_name; --------------------Line Number: 46
exit();
and Model is
function login(`$`email, `$`password, `$`remember = false) {
`$`this->db->select('*');
`$`this->db->where('email', `$`email);
`$`this->db->where('active', 1);
`$`this->db->where('password', md5(`$`password));
`$`this->db->limit(1);
`$`result = `$`this->db->get('customers');
`$`customer = `$`result->row_array();
if (`$`customer) {
// Retrieve customer addresses
`$`this->db->where(array('customer_id' => `$`customer['id'], 'id' => `$`customer['default_billing_address']));
`$`address = `$`this->db->get('customers_address_bank')->row_array();
if (`$`address) {
$fields = unserialize($address['field_data']);
$customer['bill_address'] = $fields;
$customer['bill_address']['id'] = $address['id']; // save the addres id for future reference
}
$this->db->where(array('customer_id' => $customer['id'], 'id' => $customer['default_shipping_address']));
$address = $this->db->get('customers_address_bank')->row_array();
if ($address) {
$fields = unserialize($address['field_data']);
$customer['ship_address'] = $fields;
$customer['ship_address']['id'] = $address['id'];
} else {
$customer['ship_to_bill_address'] = 'true';
}
// Set up any group discount
if ($customer['group_id'] != 0) {
$group = $this->get_group($customer['group_id']);
if ($group) { // group might not exist
if ($group->discount_type == "fixed") {
$customer['group_discount_formula'] = "- " . $group->discount;
} else {
$percent = (100 - (float) $group->discount) / 100;
$customer['group_discount_formula'] = '* (' . $percent . ')';
}
}
}
if (!$remember) {
$customer['expire'] = time() + $this->session_expire;
} else {
$customer['expire'] = false;
}
// put our customer in the cart
$this->go_cart->save_customer($customer);
return $customer;
} else {
return false;
}
}

If you did a var_dump on your login variable you will see that it is an array not an object so you can't deal with it like an object.
so go to your model and modify the following:
$customer = $result->row_array();
to be:
$customer['result'] = $result->row_array();
then in line 46 use it as:
$login['result']->last_name;
Why this is happening:
because as you defined $customer as an object at first. you also redefined it later in your model as an array by using $customer['something'] pattern of assignation.
So you can't have it your way, it's either an array or an object.

//You used this code because row_array return array not object
`$`login["result"] = `$`this->Customer_model->login(`$`email, `$`password, `$`remember);
echo $login['result']["last_name"];

Related

How can i Create a utility function for check null value coming from CSV and replace to print NULL

This is the function I have used to print NULL but I want to check all values in one function and replace where there is no value than print NULL in the database and I am using Codeigniter.
$candidate = $this->csvreader->parse_file($_FILES['file']['tmp_name']);
foreach($candidate as $row){
if(empty($row['EMAIL_ADDRESS']))
{
$email = NULL;
}
else
{
$email = $row['EMAIL_ADDRESS'];
}
if(empty($row['CONTACT_NO']))
{
$contact_no = NULL;
}
else
{
$contact_no = $row['CONTACT_NO'];
}
if(empty($row['RECEIVE_DATE']))
{
$receive_date = NULL;
}
else
{
$receive_date = $row['RECEIVE_DATE'];
}
if(empty($row['SELENIUM']))
{
$selenium = NULL;
}
else
{
$selenium = $row['SELENIUM'];
}
}
My Array Looks Like This
Array
(
[CANDIDATE_CODE] => XYZ
[CANDIDATE_NAME] => XYZ
[CONTACT_NO] =>
[EMAIL_ADDRESS] =>
[SOURCE] => XYZ
[RECEIVE_DATE] =>
[CURRENT_STATUS] => XYZ
[INTERVIEW_DATE] => 2019-05-04
[JAVA_PROGRAMMING] =>
[COMMUNICATION] =>
[CONCEPTUAL_KNOWLEDGE] =>
[COMMENT_1] => abc
[STATUS_1ST_ROUND] =>
[TEST_DATE] =>
[TEST_PLATFORM] =>
[TEST_SCORE] =>
[COMMENT_2] =>
[STATUS_2ND_ROUND] =>
[3RD_ROUND_DATE] =>
[COMMENT_3] =>
[STATUS_3RD_ROUND] =>
[DATE] =>
[COMMENT_4] =>
[FINAL_DATE] =>
[COMMENT_5] =>
)
in the array there is many null value so i have to put NULL in the database how can i do this in function call
The solution is to have the database use NULL as the default field values. Then if not data is provided during insert/update then, when the row is retrieved, the values returned will be NULL and you won't need all those checks.
$data2 = array('CANDIDATE_CODE' => 'XYZ','CONTACT_NO' => '');
$data2 = array_map(function($value_) { return ($value_ == null) ? 'null' : trim($value_); }, $data2);
print_r($data2);
Array ( [CANDIDATE_CODE] => XYZ [CONTACT_NO] => null )

Controller function does not display the return value inside foreach

I am getting my query output in the model and sending to controller If I check the data in the controller like print_r($result);
I am getting the output from my Model and My output is
stdClass Object
(
[membership_id] => 11
[member_id] => 10
[customer_id] =>21
[membership_approve] => 1
[membership_status] => 1
[profile_pic] =>
[first_name] => Juvin
[middle_name] => kumar
[last_name] => choudhary
[email] => juvin#gmail.com
[dob] => 2018-07-01
[phone] => 01236541254
[is_Approved] => 1
)
Model code is
if ($result) {
foreach($result as $result_set ){
if($result_set->membership_status == 1)
{
$result2=$this->db->select('*')
->from('membership_details')
->join('members','members.member_id = membership_details.member_id')
->group_start()
->where('members.is_Approved',1)
->where('membership_details.membership_status', 1)
->where('membership_details.member_id',$result_set->member_id)
->group_end()
->get()
->row();
return $result2;
}
else
{
return 0;
}
}
}
else{echo "Not working";}
Now I am on the controller. I am passing the output in the foreach but when I check $row->phone then it's showing meMessage: Trying to get property of non-object`
$result=$this->Search_model->check_membership($customer_name,$customer_mobile);
$arr_result2 = array();
if (count($result) > 0)
{
print_r($result);// It's displaying the same output which I aaded in the question.
foreach($result as $row){
print_r($row->customer_id);// not getting customer id
$arr_result2[] = array(
"profile_pic" => $row->profile_pic,
"name" => $row->first_name.' ' .$row->last_name,
"phone" => $row->phone
);
}
}
else{echo "No data availble";}
//print_r($arr_result2);
echo json_encode($arr_result2);
Hope this will help you :
row() fetches single record so u don't need to loop it do like this :
$result = $this->Search_model->check_membership($customer_name,$customer_mobile);
$arr_result2 = array();
if (count($result) > 0)
{
print_r($result);// It's displaying the same output which I aaded in the question.
$arr_result2[] = array(
"profile_pic" => $result->profile_pic,
"name" => $result->first_name.' ' .$result->last_name,
"phone" => $result->phone
);
}
else
{
echo "No data availble";
}
//print_r($arr_result2);
echo json_encode($arr_result2);

Foreach array to update table of database use those element of array

How to get the first value of element of array in php.
My story board is like this:
I have an array like this:
(
[0] => Array
(
[ID] => 68
[MATERIAL] => I have
[AC] => Try
)
[1] => Array
(
[ID] => 69
[MATERIAL] => It
[AC] => No Surrender
)
)
I want to update some record on my database like this,
foreach element of array,
UPDATE MY TABEL SET MATERIAL = [MATERIAL], AC = [AC] where id= [id]
this is the model named m_admin :
public function update_eir_to_cost($id, $material, $ac) {
$data = array(
"MATERIAL" => $material,
"AC" => $ac);
$this->db->trans_start();
$this->db->where($id);
$this->db->update('tb_repair_detail', $data);
$this->db->trans_complete();
if ($this->db->trans_status() === FALSE) {
// generate an error... or use the log_message() function to log your error
echo "Error Updating";
} else {
echo "Alhamdulillah";
}
}
This is the controller :
public function update_json_detail() {
$post_data = $this->input->post("POST_ARRAY");
$execute = array();
foreach ($post_data as $data) {
$execute[] = array(
'ID'=> $data['0'],
'MATERIAL' => $data['7'],
'AC' => $data['8']
);
}
echo "<pre>";
print_r($execute); // return an array like above.
/*forech element
update table using model
*/
}
This will solve your problem:
public function update_json_detail() {
$post_data = $this->input->post("POST_ARRAY");
$execute = array();
foreach ($post_data as $data) {
$execute[] = array(
'ID'=> $data['0'],
'MATERIAL' => $data['7'],
'AC' => $data['8']
);
}
echo "<pre>";
print_r($execute); // return an array like above.
$this->load->model('m_admin');
foreach ($execute as $row) {
$this->m_admin->update_eir_to_cost($row['ID'], $row['MATERIAL'], $row['AC']);
}
}

Saving Array Variable From Oracle Query

I am creating a function that extract all rows from a column with parameters and returning them as an array. So when user needed to call that function to fill in a select dropdown, the function will read from several parameters and display them in an array. but im getting an error. please help me
my function is ,
function QueryParam($conn, $data, $table){
static $stmt = array();
$firstParam = TRUE;
$query = 'SELECT * FROM ' . $table;
foreach ($data as $key => $value){
if ($firstParam){
$firstParam = FALSE;
$query .= ' WHERE ';
} else {
$query .= ' AND ';
}
$query .= "$key = :b$key";
}
$queryhash = md5($query);
if (is_null($stmt[$queryhash])) {
$stmt[$queryhash] = oci_parse($conn, $query);
}
foreach ($data as $key => $value) {
oci_bind_by_name($firstStmt[$queryhash], ":b$key", $data[$key], -1);
}
oci_execute($stmt[$queryhash], OCI_DEFAULT);
return oci_fetch_array($stmt[$queryhash], OCI_ASSOC);
}
And I am calling that function
$test = QueryParam($conn, "PROJECT_NAME = LPIEXTMILLHOUSE", "MASTER_DRAWING");
print_r($test);
The errors I am getting are,
Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\WeltesProjectManagement\lib\GeneralFunction.php on line 47
Notice: Undefined index: a8961369da6bc0fd60c573021c17ddc2 in C:\xampp\htdocs\WeltesProjectManagement\lib\GeneralFunction.php on line 59
Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\WeltesProjectManagement\lib\GeneralFunction.php on line 63
Array ( [HEAD_MARK] => IGG-SW-CP1 [ENTRY_DATE] => 18-SEP-14 [COMP_TYPE] => CANOPY [WEIGHT] => 35.8 [SURFACE] => 2 [PROFILE] => L50*50*5 [PROJECT_NAME] => SUGARWHOUSE [LENGTH] => 3040 [TOTAL_QTY] => 1 [SUBCONT_STATUS] => ASSIGNED [DWG_STATUS] => ACTIVE [REV] => 0 [DISTRIBUTION_COUNT] => 1 )
The result only returning 1 row of array, the result should be more than 1 row

PHP get value from array->value

I have this code:
function factuur_get_cardetails($form, &$form_state) {
//dd('getting cardetails');
$commands = array();
$i = 0;
foreach ($form_state['values']['field_invoice_line_deukendokter']['und'] as $line) {
if (count($line) > 1) {
// car
//dd($line);
// veld uitlezen
$kenteken = $line['field_invoice_carlicensenumber']['und'][0]['value'];
//dd($kenteken);
$url = 'https://api.datamarket.azure.com/opendata.rdw/VRTG.Open.Data/v1/KENT_VRTG_O_DAT?$filter=Kenteken%20eq%20%27'."$kenteken".'%27';
$xml = simplexml_load_file($url);
foreach($xml->entry as $entry){
$properties = $entry->content->children('http://schemas.microsoft.com/ado/2007/08/dataservices/metadata');
$auto = $properties->properties->children('http://schemas.microsoft.com/ado/2007/08/dataservices');
dd($auto->Handelsbenaming[0]);
$model = 'field_invoice_line_deukendokter[und]['.$i.'][field_invoice_carmodel][und][0][value]';
$id = "input[name='".$model."']";
$commands[] = ajax_command_invoke($id, 'val', array($auto->Handelsbenaming));
}
}
$i+=1;
}
return array('#type' => 'ajax', '#commands' => $commands);
}
The problem is when its gives me back [Object object] in my textbox while using
$commands[] = ajax_command_invoke($id, 'val', array($auto->Handelsbenaming));
Tho when i make a log using dd($auto) i get this
SimpleXMLElement Object
(
[Brandstofverbruikbuitenweg] => 3.20
[Brandstofverbruikgecombineerd] => 3.60
[Brandstofverbruikstad] => 4.30
[Catalogusprijs] => 20916
[Cilinderinhoud] => 1560
[CO2uitstootgecombineerd] => 95
[Datumaanvangtenaamstelling] => 2011-07-19T00:00:00
[DatumeersteafgifteNederland] => 2011-07-19T00:00:00
[Datumeerstetoelating] => 2011-07-19T00:00:00
[Eerstekleur] => GRIJS
[G3installatie] => N.v.t.
[Handelsbenaming] => DS3
)
So it somehow doesn't give me the value in "Handelsbenaming" and i don't know why.
Does anyone have an idea?
When i make a log dd($auto->Handelsbenaming);
it gives me this
SimpleXMLElement Object
(
[0] => DS3
)
but in my textbox it says [Object object] instead of DS3

Categories