$query = "Insert Into dbo_dailyline (Entry_date, Work_Center, Shift_Length, Number_Sewers, Deduct_Hours, Garment_Type, Other, Quantity, Notes)
values ('" .$Entry_Date. "', '" . $Shift_Length . "', '" .$Coats . "', '" . $Number_Sewers . "', '" . $Deduct_Hours . "', '" . $Garment_Type . "' , '" . $Garment_Type . "', '" . $Other . "', '" . $Quantity . "', '" . $Notes . "')";
error Column count doesn't match value count at row 1
You have two time $Garment_Type remove one
$query = "Insert Into dbo_dailyline (
Entry_date
, Work_Center
, Shift_Length
, Number_Sewers
, Deduct_Hours
, Garment_Type
, Other
, Quantity
, Notes)
values ('" .
$Entry_Date. "', '" .
$Shift_Length . "', '" .
$Coats . "', '" .
$Number_Sewers . "', '" .
$Deduct_Hours . "', '" .
$Garment_Type . "' , '" .
$Other . "', '" .
$Quantity . "', '" .
$Notes . "')";
I've been trying to figure this out, and was not able to make it work. I was trying to see the response of my PHP but it doesn't show any errors. Last time this inserted into my table. below this is query of my PHP.
$selectCharacter = $con->query('SELECT * FROM users_characters WHERE UserId = "'. $UserID .'" AND CharacterID = "'. $CharacterID .'"');
$user_data = $selectCharacter->fetch_assoc();
$CharacterID = $user_data['CharacterID'];
$UserID = $user_data['UserId'];
$Name = $user_data['Name'];
$Hash = $user_data['Hash'];
$HairID = $user_data['HairID'];
$Access = $user_data['Access'];
$SkillPoints = $user_data['SkillPoints'];
$RaceID = $user_data['RaceID'];
$RaceXP = $user_data['RaceXP'];
$ActivationFlag = $user_data['ActivationFlag'];
$PermamuteFlag = $user_data['PermamuteFlag'];
$Country = $user_data['Country'];
$Age = $user_data['Age'];
$Gender = $user_data['Gender'];
$Email = $user_data['Email'];
$Level = $user_data['Level'];
$Copper = $user_data['Copper'];
$Silver = $user_data['Silver'];
$Gold = $user_data['Gold'];
$Coins = $user_data['Coins'];
$Exp = $user_data['Exp'];
$ColorHair = $user_data['ColorHair'];
$ColorSkin = $user_data['ColorSkin'];
$ColorEye = $user_data['ColorEye'];
$ColorBase = $user_data['ColorBase'];
$ColorTrim = $user_data['ColorTrim'];
$ColorAccessory = $user_data['ColorAccessory'];
$SlotsBag = $user_data['SlotsBag'];
$SlotsBank = $user_data['SlotsBank'];
$SlotsHouse = $user_data['SlotsHouse'];
$DateCreated = $user_data['DateCreated'];
$LastLogin = $user_data['LastLogin'];
$CpBoostExpire = $user_data['CpBoostExpire'];
$RepBoostExpire = $user_data['RepBoostExpire'];
$GoldBoostExpire = $user_data['GoldBoostExpire'];
$ExpBoostExpire = $user_data['ExpBoostExpire'];
$UpgradeExpire = $user_data['UpgradeExpire'];
$UpgradeDays = $user_data['UpgradeDays'];
$Upgraded = $user_data['Upgraded'];
$Achievement = $user_data['Achievement'];
$Settings = $user_data['Settings'];
$Quests = $user_data['Quests'];
$Quests2 = $user_data['Quests2'];
$DailyQuests0 = $user_data['DailyQuests0'];
$DailyQuests1 = $user_data['DailyQuests1'];
$DailyQuests2 = $user_data['DailyQuests2'];
$MonthlyQuests0 = $user_data['MonthlyQuests0'];
$LastArea = $user_data['LastArea'];
$SpawnPoint = $user_data['SpawnPoint'];
$CurrentServer = $user_data['CurrentServer'];
$HouseInfo = $user_data['HouseInfo'];
$KillCount = $user_data['KillCount'];
$DeathCount = $user_data['DeathCount'];
$Address = $user_data['Address'];
$Language = $user_data['Language'];
$Rebirth = $user_data['Rebirth'];
$Bounty = $user_data['Bounty'];
$backupCharacter = $con->query("INSERT INTO `users_characters_history`
(`CharacterID`, `UserId`, `Name`, `Hash`, `HairID`,
`Access`, `SkillPoints`, `RaceID`, `RaceXP`,
`ActivationFlag`, `PermamuteFlag`, `Country`,
`Age`, `Gender`, `Email`, `Level`, `Copper`, `Silver`,
`Gold`, `Coins`, `Exp`, `ColorHair`, `ColorSkin`,
`ColorEye`, `ColorBase`, `ColorTrim`, `ColorAccessory`,
`SlotsBag`, `SlotsBank`, `SlotsHouse`, `DateCreated`,
`LastLogin`, `CpBoostExpire`, `RepBoostExpire`,
`GoldBoostExpire`, `ExpBoostExpire`, `UpgradeExpire`,
`UpgradeDays`, `Upgraded`, `Achievement`, `Settings`,
`Quests`, `Quests2`, `DailyQuests0`, `DailyQuests1`,
`DailyQuests2`, `MonthlyQuests0`, `LastArea`, `SpawnPoint`,
`CurrentServer`, `HouseInfo`, `KillCount`, `DeathCount`,
`Address`, `Language`, `Rebirth`, `Bounty`)
VALUES ('" . $CharacterID . "', '" . $UserID . "', '" . $Name ."', '"
. $Hash . "', '" . $HairID . "', '" . $Access . "', '"
. $SkillPoints . "', '" . $RaceID . "', '" . $RaceXP
. "', '" . $ActivationFlag . "', '" . $PermamuteFlag . "', '"
. $Country . "', '" . $Age . "', '" . $Gender ."', '" .
$Email . "', '" . $Level . "', '" . $Copper . "', '" .
$Silver . "', '" . $Gold . "', '" . $Coins . "', '" . $Exp .
"', '" . $ColorHair . "', '" . $ColorSkin . "', '" .
$ColorEye . "', '" . $ColorBase . "', '" . $ColorTrim . "',
'" . $ColorAccessory . "', '" . $SlotsBag . "', '" .
$SlotsBank . "','" . $SlotsHouse . "', '" . $DateCreated .
"', '" . $LastLogin . "', '" . $CpBoostExpire . "', '" .
$RepBoostExpire . "', '" . $GoldBoostExpire . "', '" .
$ExpBoostExpire . "', '" . $UpgradeExpire . "', '" .
$UpgradeDays . "', '" . $Upgraded ."', '" . $Achievement .
"', '" . $Settings . "', '" . $Quests . "', '" . $Quests2 .
"', '" . $DailyQuests0 . "', '" . $DailyQuests1 . "', '" .
$DailyQuests2 . "', '" . $MonthlyQuests0 . "', '" . $LastArea
. "', '" . $SpawnPoint . "', '" . $CurrentServer . "', '" .
$HouseInfo . "', '" . $KillCount . "', '" . $DeathCount . "',
'" . $Address . "', '" . $Language . "', '" . $Rebirth . "',
'" . $Bounty ."')");
This is the query that should insert but won't insert, the network logs in chrome doesn't show the error of my query.
$backupCharacter = $con->query("INSERT INTO `users_characters_history` (`CharacterID`, `UserId`, `Name`, `Hash`, `HairID`, `Access`, `SkillPoints`, `RaceID`, `RaceXP`, `ActivationFlag`, `PermamuteFlag`, `Country`, `Age`, `Gender`, `Email`, `Level`, `Copper`, `Silver`, `Gold`, `Coins`, `Exp`, `ColorHair`, `ColorSkin`, `ColorEye`, `ColorBase`, `ColorTrim`, `ColorAccessory`, `SlotsBag`, `SlotsBank`, `SlotsHouse`, `DateCreated`, `LastLogin`, `CpBoostExpire`, `RepBoostExpire`, `GoldBoostExpire`, `ExpBoostExpire`, `UpgradeExpire`, `UpgradeDays`, `Upgraded`, `Achievement`, `Settings`, `Quests`, `Quests2`, `DailyQuests0`, `DailyQuests1`, `DailyQuests2`, `MonthlyQuests0`, `LastArea`, `SpawnPoint`, `CurrentServer`, `HouseInfo`, `KillCount`, `DeathCount`, `Address`, `Language`, `Rebirth`, `Bounty`)
VALUES ('" . $CharacterID . "', '" . $UserID . "', '" . $Name ."', '" . $Hash . "', '" . $HairID . "', '" . $Access . "', '" . $SkillPoints . "', '" . $RaceID . "', '" . $RaceXP . "', '" . $ActivationFlag . "', '" . $PermamuteFlag . "', '" . $Country . "', '" . $Age . "', '" . $Gender ."', '" . $Email . "', '" . $Level . "', '" . $Copper . "', '" . $Silver . "', '" . $Gold . "', '" . $Coins . "', '" . $Exp . "', '" . $ColorHair . "', '" . $ColorSkin . "', '" . $ColorEye . "', '" . $ColorBase . "', '" . $ColorTrim . "', '" . $ColorAccessory . "', '" . $SlotsBag . "', '" . $SlotsBank . "','" . $SlotsHouse . "', '" . $DateCreated . "', '" . $LastLogin . "', '" . $CpBoostExpire . "', '" . $RepBoostExpire . "', '" . $GoldBoostExpire . "', '" . $ExpBoostExpire . "', '" . $UpgradeExpire . "', '" . $UpgradeDays . "', '" . $Upgraded ."', '" . $Achievement . "', '" . $Settings . "', '" . $Quests . "', '" . $Quests2 . "', '" . $DailyQuests0 . "', '" . $DailyQuests1 . "', '" . $DailyQuests2 . "', '" . $MonthlyQuests0 . "', '" . $LastArea . "', '" . $SpawnPoint . "', '" . $CurrentServer . "', '" . $HouseInfo . "', '" . $KillCount . "', '" . $DeathCount . "', '" . $Address . "', '" . $Language . "', '" . $Rebirth . "', '" . $Bounty ."')");
Thanks to everyone, $con->error showed the error and I was able to solve the problem, the column only accepts 6 characters and the one i'm inserting which is ColorHair has 9 characters, I changed its Length and was able to insert the item.
Hey Guys I am trying to pass data to my model, but for some reason I keep getting an "undefined customitem_id" in my model file. I am testing to see if it will even send to the model so:
the code is as follows. My controller file from customer.php file
$data['customitem_id']= 19;
if(isset($this->request->post['customitem_id'])) {
$this->request->post['customitem_id'];
}
My code from:
public function editCustomer($customer_id, $data) {
if (!isset($data['custom_field'])) {
$data['custom_field'] = array();
}
$this->db->query("UPDATE " . DB_PREFIX . "customer SET customer_group_id = '" . (int)$data['customer_group_id'] . "', sales_representative = '" . $this->db->escape($data['username']) . "', firstname = '" . $this->db->escape($data['firstname']) . "', lastname = '" . $this->db->escape($data['lastname']) . "', email = '" . $this->db->escape($data['email']) . "', telephone = '" . $this->db->escape($data['telephone']) . "', fax = '" . $this->db->escape($data['fax']) . "', custom_field = '" . $this->db->escape(isset($data['custom_field']) ? serialize($data['custom_field']) : '') . "', newsletter = '" . (int)$data['newsletter'] . "', status = '" . (int)$data['status'] . "', approved = '" . (int)$data['approved'] . "', safe = '" . (int)$data['safe'] . "' WHERE customer_id = '" . (int)$customer_id . "'");
$this->db->query("UPDATE " . DB_PREFIX . "custom_item SET customer_id = '" . (int)$customer_id . "' WHERE customitem_id = '" . (int)$customitem_id . "'");
it keeps giving me an undefined variable in the model file. How would I go about making sure it sends the data?
Thanks for your help.
Looks like you're passing an array $data to your editCustomer($customer_id, $data) right?
Try changing this from:
$this->db->query("UPDATE " . DB_PREFIX . "custom_item SET customer_id = '" . (int)$customer_id . "' WHERE customitem_id = '" . (int)$customitem_id . "'")
to
$this->db->query("UPDATE " . DB_PREFIX . "custom_item SET customer_id = '" . (int)$customer_id . "' WHERE customitem_id = '" . (int)$data['customitem_id'] . "'")
note that I changed (int)$customitem_id to (int)$data['customitem_id']
You're using variable $customitem_id in your model but in your controller it is $data['customitem_id']. You likely just need to change $customitem_id to $data['customitem_id'] in your model.
I have a website in opencart the order id is jumping up.
means if a person has order something on website and his order id is 49 the order id of the next order should be 50 but it is shown as 51 or 52.
When I check in the database table oc_order it shown the same order for the missing order no.
class ModelCheckoutOrder extends Model {
public function addOrder($data) {
$this->db->query("INSERT INTO `" . DB_PREFIX . "order` SET invoice_prefix = '" . $this->db->escape($data['invoice_prefix']) . "', store_id = '" . (int)$data['store_id'] . "', store_name = '" . $this->db->escape($data['store_name']) . "', store_url = '" . $this->db->escape($data['store_url']) . "', customer_id = '" . (int)$data['customer_id'] . "', customer_group_id = '" . (int)$data['customer_group_id'] . "', emp_name = '" . $this->db->escape($data['emp_name']) . "', emp_ID = '" . $this->db->escape($data['emp_ID']) . "', email = '" . $this->db->escape($data['email']) . "', mobile_no = '" . $this->db->escape($data['mobile_no']) . "', fax = '" . $this->db->escape($data['fax']) . "', payment_emp_name = '" . $this->db->escape($data['payment_emp_name']) . "', payment_emp_ID = '" . $this->db->escape($data['payment_emp_ID']) . "', payment_company = '" . $this->db->escape($data['payment_company']) . "', payment_company_id = '" . $this->db->escape($data['payment_company_id']) . "', payment_tax_id = '" . $this->db->escape($data['payment_tax_id']) . "', payment_address_1 = '" . $this->db->escape($data['payment_address_1']) . "', payment_address_2 = '" . $this->db->escape($data['payment_address_2']) . "', payment_city = '" . $this->db->escape($data['payment_city']) . "', payment_postcode = '" . $this->db->escape($data['payment_postcode']) . "', payment_country = '" . $this->db->escape($data['payment_country']) . "', payment_country_id = '" . (int)$data['payment_country_id'] . "', payment_zone = '" . $this->db->escape($data['payment_zone']) . "', payment_zone_id = '" . (int)$data['payment_zone_id'] . "', payment_address_format = '" . $this->db->escape($data['payment_address_format']) . "', payment_method = '" . $this->db->escape($data['payment_method']) . "', payment_code = '" . $this->db->escape($data['payment_code']) . "', shipping_emp_name = '" . $this->db->escape($data['shipping_emp_name']) . "', shipping_emp_ID = '" . $this->db->escape($data['shipping_emp_ID']) . "', shipping_company = '" . $this->db->escape($data['shipping_company']) . "', shipping_address_1 = '" . $this->db->escape($data['shipping_address_1']) . "', shipping_address_2 = '" . $this->db->escape($data['shipping_address_2']) . "', shipping_city = '" . $this->db->escape($data['shipping_city']) . "', shipping_postcode = '" . $this->db->escape($data['shipping_postcode']) . "', shipping_country = '" . $this->db->escape($data['shipping_country']) . "', shipping_country_id = '" . (int)$data['shipping_country_id'] . "', shipping_zone = '" . $this->db->escape($data['shipping_zone']) . "', shipping_zone_id = '" . (int)$data['shipping_zone_id'] . "', shipping_address_format = '" . $this->db->escape($data['shipping_address_format']) . "', shipping_method = '" . $this->db->escape($data['shipping_method']) . "', shipping_code = '" . $this->db->escape($data['shipping_code']) . "', comment = '" . $this->db->escape($data['comment']) . "', total = '" . (float)$data['total'] . "', affiliate_id = '" . (int)$data['affiliate_id'] . "', commission = '" . (float)$data['commission'] . "', language_id = '" . (int)$data['language_id'] . "', currency_id = '" . (int)$data['currency_id'] . "', currency_code = '" . $this->db->escape($data['currency_code']) . "', currency_value = '" . (float)$data['currency_value'] . "', ip = '" . $this->db->escape($data['ip']) . "', forwarded_ip = '" . $this->db->escape($data['forwarded_ip']) . "', user_agent = '" . $this->db->escape($data['user_agent']) . "', accept_language = '" . $this->db->escape($data['accept_language']) . "', date_added = NOW(), date_modified = NOW()");
$this->db->query("INSERT INTO " . DB_PREFIX . "order_history SET order_id = '" . (int)$order_id . "', order_status_id = '" . (int)$order_status_id . "', notify = '1', comment = '" . $this->db->escape(($comment && $notify) ? $comment : '') . "', date_added = NOW()");
$order_product_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_product WHERE order_id = '" . (int)$order_id . "'");
foreach ($order_product_query->rows as $order_product) {
$this->db->query("UPDATE " . DB_PREFIX . "product SET quantity = (quantity - " . (int)$order_product['quantity'] . ") WHERE product_id = '" . (int)$order_product['product_id'] . "' AND subtract = '1'");
$order_option_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_option WHERE order_id = '" . (int)$order_id . "' AND order_product_id = '" . (int)$order_product['order_product_id'] . "'");
foreach ($order_option_query->rows as $option) {
$this->db->query("UPDATE " . DB_PREFIX . "product_option_value SET quantity = (quantity - " . (int)$order_product['quantity'] . ") WHERE product_option_value_id = '" . (int)$option['product_option_value_id'] . "' AND subtract = '1'");
}
}
this is because there is a difference between what you see in the database itself and what you see in the orders admin page. and this difference is due to the fact that opencart stores something called a missing order id, and that happens for example one someone fills all the details and then by mistake he just reloads the checkout page and then he just press the "confirm" button. at this case for example in the orders admin page he booked two orders number and you will only see the second number - ofc the number of order ids skipped is the same as the number of missing orders stored by opencart itself.
if you want to test this go to checkout page and fill all orders and then confirm it, at this case you wont see any difference, however if you go to checkout page fill all info and then reload the page and then just press confirm you will see that the order id will skip one number.
in opencart database you wont see missing order ids, because opencart insert an order in the database only if it was confirmed.
I am able to retrieve data from a website(Nestoria) and store into my PostGIS database. However not every individual result that is returned have latitude and longitude values and as such they are not stored into the database. I tried using (pg_escape_string) so that it can return null values as double quotes(") but it didn't work. The field type of my lat and long columns in the database is "double precision".
This is a sample output of the error: ("Warning: pg_query() [function.pg-query]: Query failed: ERROR: invalid input syntax for type double precision: "" LINE 1: ...droom garden flat set in a period building with...', '', '') ^ in C:\XAMMP...\database.php on line 12")
Please see the code below for retrieving the data:
<?php
$url = ("http://api.nestoria.co.uk/api?action=search_listings¢re_point=51.5424,-0.1734,2km&listing_type=rent&property_type=all&price_min=min&price_max=max&bedroom_min=0&bedroom_max=0&number_of_results=50&has_photo=1&page=4");
$xml = simplexml_load_file($url);
foreach ($xml->response->listings as $entry) {
echo $entry->attributes()->title;
echo $entry->attributes()->bathroom_number;
echo $entry->attributes()->bedroom_number;
echo $entry->attributes()->datasource_name;
echo $entry->attributes()->guid;
echo $entry->attributes()->img_url;
echo $entry->attributes()->keywords;
echo $entry->attributes()->lister_name;
echo $entry->attributes()->listing_type;
echo $entry->attributes()->price;
echo $entry->attributes()->price_type;
echo $entry->attributes()->property_type;
echo $entry->attributes()->summary;
echo $entry->attributes()->latitude;
echo $entry->attributes()->longitude;
// Process XML file
}
?>
Find below the code to store values into database:
<?php
require 'nestoriauk.php';
// Opens a connection to a PostgresSQL server
$connection = pg_connect("dbname=postgis user=postgres password=xxxx");
// Execute query
foreach ($xml->response->listings as $entry) {
$query = "INSERT INTO nestoriaphp(title, bathroom, bedroom, datasource, guid, image, keywords, lister, listype, price, pricetype, property_type, summary, latitude, longitude) VALUES ('" . pg_escape_string($entry->attributes()->title) . "', '" . pg_escape_string($entry->attributes()->bathroom_number) . "', '" . pg_escape_string($entry->attributes()->bedroom_number) . "', '" . pg_escape_string($entry->attributes()->datasource_name) . "', '" . pg_escape_string($entry->attributes()->guid) ."', '" . pg_escape_string($entry->attributes()->img_url) . "', '" . pg_escape_string($entry->attributes()->keywords) . "', '" . pg_escape_string($entry->attributes()->lister_name) . "', '" . pg_escape_string($entry->attributes()->listing_type) . "', '" . pg_escape_string($entry->attributes()->price) . "', '" . pg_escape_string($entry->attributes()->price_type) . "', '" . pg_escape_string($entry->attributes()->property_type) ."', '" . pg_escape_string($entry->attributes()->summary) . "', '" . pg_escape_string($entry->attributes()->latitude) . "', '" . pg_escape_string($entry->attributes()->longitude) . "')";
$result = pg_query($query);
printf ("These values are inserted into the database - %s %s %s", $entry->attributes()->title, $entry->attributes()->bathroom_number, $entry->attributes()->bedroom_number, $entry->attributes()->datasource_name, $entry->attributes()->guid, $entry->attributes()->img_url, $entry->attributes()->keywords, $entry->attributes()->lister_name, $entry->attributes()->listing_type, $entry->attributes()->price, $entry->attributes()->price_type, $entry->attributes()->property_type, $entry->attributes()->summary, $entry->attributes()->latitude, $entry->attributes()->longitude);
}
pg_close();
?>
Yemi
If a POI has no lat-lon, which value it has? empty string?
assuming that an empty string is returned when there is no lat-lon.
$lon = "NULL";
if($entry->attributes()->longitude != "")
$lon = "'".$entry->attributes()->longitude."'";
$lat = "NULL";
if($entry->attributes()->latitude != "")
$lat = "'".$entry->attributes()->latitude."'";
so query looks like this:
$query = "INSERT INTO nestoriaphp(title, bathroom, bedroom, datasource, guid, image, keywords, lister, listype, price, pricetype, property_type, summary, latitude, longitude) VALUES ('" . pg_escape_string($entry->attributes()->title) . "', '" . pg_escape_string($entry->attributes()->bathroom_number) . "', '" . pg_escape_string($entry->attributes()->bedroom_number) . "', '" . pg_escape_string($entry->attributes()->datasource_name) . "', '" . pg_escape_string($entry->attributes()->guid) ."', '" . pg_escape_string($entry->attributes()->img_url) . "', '" . pg_escape_string($entry->attributes()->keywords) . "', '" . pg_escape_string($entry->attributes()->lister_name) . "', '" . pg_escape_string($entry->attributes()->listing_type) . "', '" . pg_escape_string($entry->attributes()->price) . "', '" . pg_escape_string($entry->attributes()->price_type) . "', '" . pg_escape_string($entry->attributes()->property_type) ."', '" . pg_escape_string($entry->attributes()->summary) . "', " . $lat . ", " . $lon . ")";
Note that the NULL value has no '' in sql.