Trying to get property 'parameter' of non-object - mysql
Hello i have an api in Laravel i'm trying to get a value from a table column
Json response it already in the table json response but when i get it its says:
Trying to get property 'parameter' of non-object
i'm so new on laravel so i'm really lost with this
The Function i use when i call the api
it go to
$parameter = $value->parameter;
And then stop and say in PriceDetailHolder():
Trying to get property 'parameter' of non-object
I showed 2 functions because i don't really know where is the problem exactly
public static function PriceDetailHolder($booking_prices, $booking_id = null, $currency = null): array
{
if (!empty($booking_id) && $booking_id !== null) {
/**
* #var $booking Booking
*/
$booking = Booking::query()->find($booking_id);
$currency = $booking->CountryArea->Country->isoCode;
}
$holder[] = [
'highlighted_text' => trans('admin.message665'),
'highlighted_text_color' => '333333',
'highlighted_style' => 'BOLD',
'highlighted_visibility' => true,
'small_text' => 'eee',
'small_text_color' => '333333',
'small_text_style' => '',
'small_text_visibility' => false,
'value_text' => trans('admin.message665'),
'value_text_color' => '333333',
'value_text_style' => '',
'value_textvisibility' => false
];
foreach ($booking_prices as $key => $value) {
$code = '';
if (!empty($value->code)) {
$code = "({$value->code})";
}
$parameter = $value->parameter;
/**
* #var $parameterDetails PricingParameter
*/
$parameterDetails = PricingParameter::query()->find($parameter);
if ($parameterDetails === null) {
$prameterName = $parameter;
} else {
if ((int)$parameterDetails->parameterType === 13) {
$applicable = (int)$parameterDetails->applicable === 1 ? trans('api.message174') : trans('api.message175');
/**
* #var $priceCardValue PriceCardValue
*/
$priceCardValue = PriceCardValue::query()->where([['price_card_id', '=', $value->price_card_id], ['pricing_parameter_id', '=', $parameter]])->first();
$code = "($priceCardValue->parameter_price %)\n" . $applicable;
}
$prameterName = $parameterDetails->ParameterApplication . $code;
}
$holder[] = [
'highlighted_text' => $prameterName,
'highlighted_text_color' => '333333',
'highlighted_style' => 'NORMAL',
'highlighted_visibility' => true,
'small_text' => 'eee',
'small_texot_clor' => '333333',
'small_text_style' => '',
'small_text_visibility' => false,
'value_text' => $currency . ' ' . $value->amount,
'value_text_color' => '333333',
'value_text_style' => '',
'value_textvisibility' => true
];
}
return $holder;
}
public function End(EndTripRequest $request)
{
$merchant_id = $request->user('api-driver')->merchant_id;
$validator = Validator::make($request->all(), [
'booking_id' => [
'required',
'integer',
Rule::exists('bookings', 'id')->where(static function ($query) {
$query->where('booking_status', TripStatus::STARTED);
}),
],
'latitude' => 'required',
'longitude' => 'required',
'tip_amount' => 'nullable|numeric',
]);
if ($validator->fails()) {
$errors = $validator->messages()->all();
return response()->json(['result' => '0', 'message' => $errors[0], 'data' => []]);
}
/**
* #var $configuration BookingConfiguration
*/
$configuration = BookingConfiguration::query()->where('merchant_id', $merchant_id)->first();
$booking_id = $request->booking_id;
/**
* #var $booking Booking
*/
$booking = Booking::with('PriceCard')->find($booking_id);
/**
* #var $bookingDetails BookingDetail
*/
$bookingDetails = BookingDetail::booking($booking_id)->first();
$service_type_id = (int)$booking->service_type_id;
if (!in_array($service_type_id, [1, 5], false)) {
$start_meter_value = $bookingDetails->start_meter_value;
$customMessages = [
'gt' => trans_choice('api.endmeter', 3, ['value' => $start_meter_value]),
];
$validator = Validator::make($request->all(), [
'send_meter_image' => 'required',
'send_meter_value' => 'required|integer|gt:' . $start_meter_value,
], $customMessages);
if ($validator->fails()) {
$errors = $validator->messages()->all();
return response()->json(['result' => '0', 'message' => $errors[0], 'data' => []]);
}
}
$request->user('api-driver')->free_busy = 2;
$request->user('api-driver')->total_trips += 1;
$request->user('api-driver')->save();
/**
* #var $user \App\User
*/
$user = $booking->User;
++$user->total_trips;
$user->save();
if ($request->hasFile('send_meter_image')) {
$bookingDetails->end_meter_value = $request->send_meter_value;
$request->file('send_meter_image');
$send_meter_image = $request->send_meter_image->store('service');
$bookingDetails->end_meter_image = $send_meter_image;
}
$pricing_type = $booking->PriceCard->pricing_type;
$price_card_id = $booking->price_card_id;
$key = $configuration->google_key;
$endAddress = GoogleController::GoogleLocation($request->latitude, $request->longitude, $key);
$endAddress = $endAddress ?: 'Address Not found';
$endTimeStamp = time();
$bookingDetails->end_timestamp = $endTimeStamp;
$bookingDetails->end_latitude = $request->latitude;
$bookingDetails->end_longitude = $request->longitude;
$bookingDetails->end_location = $endAddress;
$bookingDetails->accuracy_at_end = $request->accuracy;
$bookingDetails->save();
$start_timestamp = $bookingDetails->start_timestamp;
$seconds = $endTimeStamp - $start_timestamp;
$hours = floor($seconds / 3600);
$mins = floor($seconds / 60 % 60);
//$secs = floor($seconds % 60);
$timeFormat = sprintf('%02d H %02d M', $hours, $mins);
$rideTime = round(abs($endTimeStamp - $start_timestamp) / 60, 2);
$from = $bookingDetails->start_latitude . ',' . $bookingDetails->start_longitude;
$to = $request->latitude . ',' . $request->longitude;
$coordinates = '';
$bookingData = new BookingDataController();
$bookingData->ActivateRefer($booking->id);
/**
* Calculate the distance based on service type.
*/
switch ($service_type_id) {
case '1':
$bookingcoordinates = BookingCoordinate::query()->where('booking_id', $request->booking_id)->first();
$pick = $booking->pickup_latitude . ',' . $booking->pickup_longitude;
$drop = $booking->drop_latitude . ',' . $booking->drop_longitude;
$distanceCalculation = new DistanceCalculation();
$distance = $distanceCalculation->distance($from, $to, $pick, $drop, $bookingcoordinates['coordinates'], $merchant_id, $key);
$distance = round($distance);
$coordinates = $bookingcoordinates['coordinates'];
break;
case '5':
$distance = GoogleController::GoogleShortestPathDistance($from, $to, $key);
$distance = round($distance);
break;
default:
$distance = $bookingDetails->end_meter_value - $bookingDetails->start_meter_value;
$distance *= 1000;
}
/**
* Calculate Trip Amount based on Pricing Type
*/
switch ($pricing_type) {
case '1':
case '2':
$newArray = PriceController::CalculateBill($price_card_id, $distance, $rideTime, $booking_id, $bookingDetails->wait_time, (double)$bookingDetails->dead_milage_distance, (double)$booking->User->outstanding_amount);
/**
* Check if trip went through a toll gate
*/
if (!empty($configuration->toll_api)) {
$newTool = new Toll();
$toolPrice = $newTool->checkToll($configuration->toll_api, $from, $to, $coordinates, $configuration->toll_key);
if (is_array($toolPrice) && array_key_exists('cost', $toolPrice) && $toolPrice['cost'] > 0) {
$parameter[] = ['price_card_id' => $price_card_id, 'booking_id' => $booking_id, 'parameter' => 'TollCharges', 'amount' => sprintf('%0.2f', $toolPrice['cost']), 'type' => 'CREDIT', 'code' => ''];
$newArray[] = $parameter;
}
}
$newExtraCharge = new ExtraCharges();
$carditnewArray = array_filter($newArray, static function ($e) {
return ($e['type'] === 'CREDIT');
});
$amount = array_sum(Arr::pluck($carditnewArray, 'amount'));
if ($booking->number_of_rider > 1) {
$amount += $booking->PriceCard->extra_sheet_charge;
}
$booking_time = (int)$booking->booking_type === BookingType::RIDE_NOW ? $booking->created_at->toTimeString() : $booking->later_booking_time;
$timeCharge = $newExtraCharge->NightChargeEstimate($price_card_id, $booking_id, $amount, $booking_time);
if (!empty($timeCharge)) {
$charge = array_sum(Arr::pluck($timeCharge, 'amount'));
$amount += $charge;
$newArray = array_merge($newArray, $timeCharge);
}
/**
* Check and calculate surge price
*/
if ((int)$booking->PriceCard->sub_charge_status === 1) {
$surge = (int)$booking->PriceCard->sub_charge_type === 1 ? $booking->PriceCard->sub_charge_value : bcdiv($amount, $booking->PriceCard->sub_charge_value, 2);
$amount += $surge;
$parameter = ['price_card_id' => $price_card_id, 'booking_id' => $booking_id, 'parameter' => 'Surge-Charge', 'amount' => sprintf('%0.2f', $surge), 'type' => 'CREDIT', 'code' => ''];
$newArray[] = $parameter;
}
$discoutArray = array_filter($newArray, static function ($e) {
return ($e['type'] === 'DEBIT');
});
/**
* Check if there's a promo code applied to this booking
*/
if (!empty($discoutArray)) {
$promoDiscount = sprintf('%0.2f', array_sum(Arr::pluck($discoutArray, 'amount')));
$bookingDetails->promo_discount = $promoDiscount;
$amount = $amount > $promoDiscount ? $amount - $promoDiscount : '0.00';
} else {
$bookingDetails->promo_discount = '0.00';
}
/**
* Check if a driver or user is referee
*/
$referDiscount = $bookingData->Refer($booking->user_id);
if ($referDiscount !== NULL) {
switch ($referDiscount->offer_type) {
case '1':
$referAmount = $amount;
$amount = 0;
break;
case '2':
$referAmount = ($amount * $referDiscount->referral_offer_value) / 100;
$amount -= $referAmount;
break;
case '3':
$referAmount = $referDiscount->referral_offer_value;
$amount = $amount < $referAmount ? 0 : $amount - $referAmount;
break;
default:
$referAmount = 0;
break;
}
$parameter[] = ['price_card_id' => $price_card_id, 'booking_id' => $booking_id, 'parameter' => 'Promotion', 'amount' => sprintf('%0.2f', $referAmount), 'type' => 'DEBIT', 'code' => ''];
array_push($newArray, $parameter);
}
$billDetails = json_encode($newArray);
$bookingDetails->total_amount = sprintf('%0.2f', $amount);
$payment = new Payment();
if ($amount > 0) {
$payment->MakePayment($booking->id, $booking->payment_method_id, $amount, $booking->user_id, $booking->card_id);
} else {
$payment->UpdateStatus($booking->id);
}
$bookingDetails->bill_details = $billDetails;
$bookingDetails->save();
\App\Http\Controllers\Helper\CommonController::Commission($booking_id, $amount);
if ($booking->User->outstanding_amount) {
User::query()->where('id', $booking->user_id)->update(['outstanding_amount' => NULL]);
}
break;
case '3':
$amount = '';
break;
default:
$amount = '';
break;
}
if ($service_type_id === 5) {
$poolRide = new PoolController();
$poolRide->DropPool($booking, $request);
}
$distance = round($distance / 1000, 2) . ' Km';
$booking->booking_status = TripStatus::COMPLETED;
$booking->travel_distance = $distance;
$booking->travel_time = $timeFormat;
$booking->travel_time_min = $rideTime;
$booking->final_amount_paid = sprintf('%0.2f', $amount);
$booking->save();
$user_id = $booking->user_id;
$message = 'Driver End Ride';
$userdevices = UserDevice::getLastDevice($booking->user_id);
$playerids = [$userdevices->player_id];
$data = $bookingData->BookingNotification($booking);
Onesignal::UserPushMessage($playerids, $data, $message, 1, $booking->merchant_id);
return response()->json(['result' => '1', 'message' => trans('api.message15'), 'data' => $booking]);
}
Its coming from a table
[{"price_card_id":3,"booking_id":"42540","parameter":1,"amount":"1.50","type":"CREDIT","code":""},{"price_card_id":3,"booking_id":"42540","parameter":2,"amount":"0.00","type":"CREDIT","code":""},{"price_card_id":3,"booking_id":"42540","parameter":3,"amount":"0.00","type":"CREDIT","code":""},{"price_card_id":3,"booking_id":"42540","parameter":4,"amount":"0.00","type":"CREDIT","code":""},{"price_card_id":3,"booking_id":"42540","parameter":5,"amount":"0.00","type":"DEBIT","code":""},[{"price_card_id":3,"booking_id":"42540","parameter":"Promotion","amount":10,"type":"DEBIT","code":""}]]
Please tell me to show you anything if i'm wrong i'm really sorry for my poor knowledge in all this but i'm just in the first step to learn
So a quick look at your code the code that fails is $value->parameter.
That value comes from $booking_prices, so the issue lies in the objects returned when iterating booking_prices does not have the property parameter.
You could remove the error by doing $parameter = $value->parameter ?? null; // null as default value or by figuring out why the parameter attribute does not always exist.
Related
Woocommerce - Adding Custom Fee Together in Cart
I created a function for a custom field for a fee which also multiplies depending on the amount of people booking: // Add Custom Field to Product under General function create_extra_fee_field() { $args = array( 'id' => 'park_fee', 'label' => __( 'Natl Park Entrance Fee', 'tranq-lsx-child' ), 'class' => 'tranq-custom-field', 'desc_tip' => true, 'description' => __( 'This sets the Fee that will be added to the car.', 'tranq-lsx-child' ), ); woocommerce_wp_text_input( $args ); } add_action( 'woocommerce_product_options_general_product_data', 'create_extra_fee_field' ); // Save Custom Field Data function save_extra_fee_field( $post_id ) { $product = wc_get_product( $post_id ); $title = isset( $_POST['park_fee'] ) ? $_POST['park_fee'] : ''; $product->update_meta_data( 'park_fee', sanitize_text_field( $title ) ); $product->save(); } add_action( 'woocommerce_process_product_meta', 'save_extra_fee_field' ); // Add Custom Field to Cart Totals function woo_add_cart_fee() { global $woocommerce; foreach( WC()->cart->get_cart() as $cart_items ){ // Get the WC_Product object (instance) $product = $cart_items['data']; $product_id = $product->get_id(); // get the product ID $custom_field_value = get_post_meta( $product->get_id(), 'park_fee', true ); $person = array_sum( $cart_items['booking']['_persons'] ); } $additional_fee_name = "Natl Park Entrance Fee"; $extra_fee = $custom_field_value * $person; $addedFee = false; // first check to make sure it isn’t already there foreach ( $woocommerce->cart->get_fees() as $_fee ) { if ($_fee->id == sanitize_title($additional_fee_name) ) { $_fee->amount = (float) esc_attr( $extra_fee ); } } if (!$addedFee) { $woocommerce->cart->add_fee( __($additional_fee_name, "woocommerce"), $extra_fee, $additional_fee_taxable ); } } add_action( "woocommerce_before_calculate_totals", "woo_add_cart_fee" ); The one product is making use of that custom fee while the other product isn't its set to 0 But when both are added to the cart the fee just shows 0. Is there any way to add both park fees together?
#Demonix, it is because the $custom_field_value is being overwritten with a '0' value, as the function loops through the attached products. If you add in a statement to check if the park_fee is an actual number before replacing $custom_field_value function woo_add_cart_fee() { global $woocommerce; $custom_field_value = 0; foreach( WC()->cart->get_cart() as $cart_item ) { // Get the WC_Product object (instance) $product = $cart_item['data']; $product_id = $product->get_id(); // get the product ID $temp_value = get_post_meta( $product->get_id(), 'park_fee', true ); if ( false !== $temp_value && 0 !== $temp_value && '' !== $temp_value && '0' !== $temp_value ) { $custom_field_value = $temp_value; } $person = array_sum( $cart_item['booking']['_persons'] ); } $additional_fee_name = "Natl Park Entrance Fee"; $extra_fee = $custom_field_value * $person; $addedFee = false; // first check to make sure it isn’t already there foreach ( $woocommerce->cart->get_fees() as $_fee ) { if ($_fee->id == sanitize_title($additional_fee_name) ) { $_fee->amount = (float) esc_attr( $extra_fee ); } } if (!$addedFee) { $woocommerce->cart->add_fee( __($additional_fee_name, "woocommerce"), $extra_fee, $additional_fee_taxable ); } } add_action( "woocommerce_before_calculate_totals", "woo_add_cart_fee" );
JSON to VB.NET Deserialize Coding
I have a column in a table where all the details of the bill are getting stored. My brother used PHP web project to do that. Now I am trying to deserialize in VB.NET Here is the PHP code (Controller) public function add_to_list() { $this->load->model('product_model', 'Product'); $pdts = $this->Product->get_data(true); $available = $this->in_cart($this->input->post('id')); $cart_qty = $available ? $available : 0; if (!is_numeric($this->input->post('qty')) || !$this->input->post('id')) { $res['success'] = false; $res['msg'] = "Please enter the valid input"; } else { $discount_percentage = $this->input->post('discount_percentage') ? $this->input->post('discount_percentage') : 0; $discount_rate = $pdts->selling_price * ($discount_percentage / 100); $final = $pdts->selling_price - $discount_rate; $igst = $pdts->igst; $igst_amt = calculate_price_by_precentage($this, $final, $pdts->igst); $gross = $pdts->selling_price; $total = $final + $igst_amt; // $total = $gross + $igst_amt; $available_qty = 5; $data = array( 'id' => $pdts->id, 'qty' => $this->input->post('qty'), 'price' => $pdts->final_price, 'name' => $pdts->product, 'options' => array( 'product_id' => $pdts->id, 'product_hsn' => $pdts->hsn, 'product_name' => $pdts->product, 'product_unit' => $pdts->unit, 'product_rate' => $pdts->selling_price, 'product_mrp' => $pdts->mrp, 'product_gst' => $pdts->igst, 'product_cgst' => $pdts->cgst, 'product_gst_amount' => $igst_amt * $this->input->post('qty'), 'product_net_rate' => $pdts->cost_price, 'product_qty' => $this->input->post('qty'), 'product_free' => 0, 'product_discount_percentage' => $discount_percentage, 'product_discount_rate' => $discount_rate, 'product_total' => $total * $this->input->post('qty'), 'available_qty' => $available_qty, 'category' => $pdts->category, 'rate' => $pdts->selling_price, 'gross' => $gross, 'igst' => $igst, 'cgst' => $igst / 2, 'sgst' => $igst / 2, 'igst_amount' => $igst_amt, 'cgst_amount' => $igst_amt / 2, 'sgst_amount' => $igst_amt / 2, 'total' => $total //final_price($this, $pdts->selling_price, calculate_price_by_precentage($this, $pdts->selling_price, $pdts->discount), calculate_price_by_precentage($this, $pdts->selling_price, $pdts->sgst)) ) ); $this->cart->insert($data); $this->pageViewData['final_discount'] = $this->input->post('discount') == '' ? '0' : $this->input->post('discount'); $this->pageViewData['final_discount_percentage'] = $this->input->post('discount_percentage') == '' ? '0' : $this->input->post('discount_percentage'); $this->pageViewData['ajax'] = true; $res['success'] = true; $res['msg'] = $this->load->view('order/cart_item', $this->pageViewData, true); } echo json_encode($res); } And this is how the cell Value looks. > a:1:{s:32:"b3712e169500f4754be4a6a681220a96";a:7:{s:2:"id";s:2:"69";s:3:"qty";d:1;s:5:"price";d:26.25;s:4:"name";s:28:"Seeded > Dates 200gm Wet > Dates";s:7:"options";a:26:{s:10:"product_id";s:2:"69";s:11:"product_hsn";s:8:"08041020";s:12:"product_name";s:28:"Seeded > Dates 200gm Wet > Dates";s:12:"product_unit";s:2:"GM";s:12:"product_rate";s:5:"26.25";s:11:"product_mrp";s:2:"35";s:11:"product_gst";s:2:"12";s:12:"product_cgst";s:1:"6";s:18:"product_gst_amount";d:3.149999999999999911182158029987476766109466552734375;s:16:"product_net_rate";s:5:"24.70";s:11:"product_qty";s:1:"1";s:12:"product_free";i:0;s:27:"product_discount_percentage";i:0;s:21:"product_discount_rate";d:0;s:13:"product_total";d:29.39999999999999857891452847979962825775146484375;s:13:"available_qty";i:5;s:8:"category";s:9:"AD > Seeded";s:4:"rate";s:5:"26.25";s:5:"gross";s:5:"26.25";s:4:"igst";s:2:"12";s:4:"cgst";i:6;s:4:"sgst";i:6;s:11:"igst_amount";d:3.149999999999999911182158029987476766109466552734375;s:11:"cgst_amount";d:1.5749999999999999555910790149937383830547332763671875;s:11:"sgst_amount";d:1.5749999999999999555910790149937383830547332763671875;s:5:"total";d:29.39999999999999857891452847979962825775146484375;}s:5:"rowid";s:32:"b3712e169500f4754be4a6a681220a96";s:8:"subtotal";d:26.25;}} That looks a lot to me. As a beginner, I need a big help from you guys to get this done.
PHP json_encode JSON_NUMERIC_CHECK with 5808e70581507
Hi I'm experiencing some difficulties with the json_encode function in PHP. I have an object with a hash (uniq ID) but it can have this format 5808e70581507 and because of the "e" surrounded with numbers I think json_encode is trying to set this fellow as an integer. My object looks like this : stdClass Object ( [id] => 16 [title] => userinf2 [desc] => Travail → [startoff] => 2016-10-20 05:00:00 [stop] => 2016-10-20 13:00:00 [status] => 1 [allDay] => 0 [code_mode] => M [uid] => 31250 [gid] => 502935 [recurrence_id] => [recurrence_mode] => [recurrence_repeat_every] => [recurrence_repeat_day] => [recurrence_end_mode] => [recurrence_end_date] => [recurrence_end_number] => [multiple_timeschedule_id] => 5808e70581507 [start] => 2016-10-20 05:00:00 [end] => 2016-10-20 13:00:00 [color] => #7AE7BF [className] => working uid_31250 code_mode_M gid_502935 ) Is there a way to make this working as it is ? The code : echo json_encode($events[6], JSON_NUMERIC_CHECK); var_dump($events[6]->multiple_timeschedule_id); // string(13) Assignment code : function _oms_planning_planning_get() { try { global $user; $intervenants = _oms_planning_get_cab_intervenants(); $sql = 'SELECT * FROM planning_event WHERE 1=1 AND ('; $params_sql = array(); foreach ($intervenants as $key => $a_user) { $sql .= ' uid =:uid' . $key . ' OR '; $params_sql[':uid' . $key] = $a_user->uid; } $sql = substr($sql, 0, -3); $sql .= ')'; $result = db_query($sql, $params_sql); $db_events = $result->fetchAll(); $events = array_map(function ($db_event) use ($intervenants) { $db_event->start = $db_event->startoff; $db_event->end = $db_event->stop; $db_event->color = (isset($db_event->gid) && intval($db_event->gid) > 0) ? _oms_planning_planning_get_color_from_gid($db_event->gid) : _oms_planning_planning_get_color_from_uid($intervenants, $db_event->uid); $db_event->className = ($db_event->status == 1) ? 'working ' : 'idleness '; $db_event->className .= 'uid_' . $db_event->uid . ' '; $db_event->className .= 'code_mode_' . $db_event->code_mode . ' '; $db_event->className .= 'gid_' . $db_event->gid; return $db_event; }, $db_events); return $events; } catch (Exception $e) { print_r($e); } } Mysql column type : multiple_timeschedule_id varchar(200) utf8_general_ci
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]'
for some reason i keep getting the 'SQLSTATE[HY093] error. the solution must be simple but im just no seeing it. The error says that it is in line 83 (included below) of ControllerStore.php and on line 55 of store_update.php (also included below) ControllerStore.php public function updateStore($itm) { $stmt = $this->pdo->prepare('UPDATE tbl_storefinder_stores SET store_name = :store_name, store_desc = :store_desc, lat = :lat, lon = :lon, phone_no = :phone_no, email = :email, category_id = :category_id, created_at = :created_at, updated_at = :updated_at, is_deleted = :is_deleted, idade = :idade, peso = :peso, oral = :oral, anal = :anal, dom = :dom, eles = :eles, elas = :elas, casais = :casais, acessorios = :acessorios, eventos = :eventos, viagens = :viagens, idiomas = :idiomas, horarios = :horarios, hora = :hora, locais = :locais, kiss = :kiss WHERE store_id = :store_id'); $result = $stmt->execute( array('store_name' => $itm->store_name, 'store_desc' => $itm->store_desc, 'lat' => $itm->lat, 'lon' => $itm->lon, 'phone_no' => $itm->phone_no, 'email' => $itm->email, 'category_id' => $itm->category_id, 'created_at' => $itm->created_at, 'updated_at' => $itm->updated_at, 'is_deleted' => $itm->is_deleted, 'idade' => $itm->idade, 'peso' => $itm->peso, 'oral' => $itm->oral, 'anal' => $itm->anal, 'dom' => $itm->dom, 'eles' => $itm->eles, 'elas' => $itm->elas, 'casais' => $itm->casais, 'acessorios' => $itm->acessorios, 'eventos' => $itm->eventos, 'viagens' => $itm->viagens, 'idiomas' => $itm->idiomas, 'horarios' => $itm->horarios, 'hora' => $itm->hora, 'locais' => $itm->locais, 'kiss' => $itm->kiss )); return $result ? true : false; } store_update.php if($store_id != null) { $store = $controller->getStoreByStoreId($store_id); if( isset($_POST['submit']) ) { $itm = new Store(); $itm->store_name = htmlspecialchars(trim(strip_tags($_POST['store_name']))); $store_desc = preg_replace('~[\r\n]+~', '', $_POST['store_desc']); $itm->store_desc = htmlspecialchars(trim(strip_tags($store_desc))); $itm->lat = trim(strip_tags($_POST['lat'])); $itm->lon = htmlspecialchars(trim(strip_tags($_POST['lon'])), ENT_QUOTES); $itm->created_at = time(); $itm->phone_no = htmlspecialchars(trim(strip_tags($_POST['phone_no'])), ENT_QUOTES); $itm->email = trim(strip_tags($_POST['email'])); $itm->category_id = trim(strip_tags($_POST['category_id'])); $itm->updated_at = time(); $itm->is_deleted = trim(strip_tags($_POST['is_deleted'])); $itm->idade = trim(strip_tags($_POST['idade'])); $itm->peso = trim(strip_tags($_POST['peso'])); $itm->oral = trim(strip_tags($_POST['oral'])); $itm->anal = trim(strip_tags($_POST['anal'])); $itm->dom = trim(strip_tags($_POST['dom'])); $itm->eles = trim(strip_tags($_POST['eles'])); $itm->elas = trim(strip_tags($_POST['elas'])); $itm->casais = trim(strip_tags($_POST['casais'])); $itm->acessorios = trim(strip_tags($_POST['acessorios'])); $itm->eventos = trim(strip_tags($_POST['eventos'])); $itm->viagens = trim(strip_tags($_POST['viagens'])); $itm->idiomas = trim(strip_tags($_POST['idiomas'])); $itm->horarios = trim(strip_tags($_POST['horarios'])); $itm->hora = trim(strip_tags($_POST['hora'])); $itm->locais = trim(strip_tags($_POST['locais'])); $itm->kiss = trim(strip_tags($_POST['kiss'])); $controller->updateStore($itm); echo "<script type='text/javascript'>location.href='stores.php'; </script>"; } } else { echo "<script type='text/javascript'>location.href='403.php';</script>"; }
The number of variables, does not match number of bound variables. Your are missing is_deleted in the store_update.php
Insert data with insert_batch
I'm using the following statement to insert data in mysql with codeigniter. $this->db->insert_batch($table, $query); $query is generated dynamically can have different number of columns on each array element and maybe the number of elements may differ on condition array ( 0 => array( 'column1'=>'insert1', 'column2'=>'insert2' ), 1 => array( 'column1'=>'insert1'; 'column2'=>'insert2', 'column4'=>'insert4' ) ) could this cause an error or handles codigniter from deafult? I'm building up the query as it follows foreach ($sql_xml as $children) { $children = $this->xml2array($children); foreach ($children as $index => $child) { if ($child != 'feed_id') { $keys[$index] = $child; } } } switch (strtolower($this->config[0]->affiliate)) { case 'case1': $target_xml = $target_xml->productItems; break; case 'case2': $target_xml = $target_xml; break; default : break; } $query = array(); $data = array(); foreach ($target_xml as $feeds) { $feeds = $this->xml2array($feeds); $columns = new RecursiveIteratorIterator(new RecursiveArrayIterator($feeds)); foreach ($columns as $index => $column) { if (array_key_exists($index, $keys)) { if($column != ''){ $data[$keys[$index]] = $column; $data['feed_id'] = $this->id; } //*TODO //$data['affiliate'] = "'.$this->config[0]->affiliate.'"; } } $query[] = $data; } if (count($query > 0)) { foreach ($query as $t){ $this->db->insert($table, $t); } }
The array's would need to have the same amount of "columns". So what I would recommend is the following (setting certain columns to null if no there is no data): array ( 0 => array( 'column1' => 'insert1', 'column2' => 'insert2', 'column3' => null, 'column4' => null ), 1 => array( 'column1' => 'insert1', 'column2' => 'insert2', 'column3' => 'insert3', 'column4' => 'insert4' ) ) Also, your syntax is invalid and it would cause an error since you are using a ; instead of an , on the first column insert.