anothernut Posted February 7, 2010 Share Posted February 7, 2010 Hi Guys, I have been working on a script to pull in xml product data into an ecommerce store and all works great except that I am having issues with updating the products attributes. These are the errors that I receive when running the script: No products options id returned for INSERT INTO products_options(language_id, products_options_name) VALUES ('1', 'Design'), although the query was successful. [sql failure] No products options values id returned for INSERT INTO products_options_values(language_id, products_options_values_id, products_options_values_name) VALUES ('1', '', 'Assorted'), although the query was successful. [sql failure] REPLACE INTO products_options_values_to_products_options(products_options_id, products_options_values_id) VALUES (, ) [sql failure] INSERT INTO products_attributes(products_id, options_id, options_values_id, options_values_price, price_prefix) VALUES (6, , , 0, '+')\r\nArray [sql failure] INSERT INTO products_options_values(language_id, products_options_values_id, products_options_values_name) VALUES ('1', '', 'Pink')\r\nArray [sql failure] REPLACE INTO products_options_values_to_products_options(products_options_id, products_options_values_id) VALUES (, ) [sql failure] INSERT INTO products_attributes(products_id, options_id, options_values_id, options_values_price, price_prefix) VALUES (6, , , 0, '+')\r\nArray [sql failure] INSERT INTO products_options_values(language_id, products_options_values_id, products_options_values_name) VALUES ('1', '', 'YELLOW')\r\nArray [sql failure] REPLACE INTO products_options_values_to_products_options(products_options_id, products_options_values_id) VALUES (, ) [sql failure] INSERT INTO products_attributes(products_id, options_id, options_values_id, options_values_price, price_prefix) VALUES (6, , , 0, '+')\r\nArray[/quote] Now I can see the glaringly obvious data that is missing from the above sql however I am jiggered if I can find what the problems are with my code and the more I stare at it the less I see lol Any chance one of you guys could have a quick look over the code for me please. [code=php:0]<?php //The english language ID define('LANGUAGE_ID', 1); define('SUPPLIER_CODE', 'PUCKATOR'); define('DEBUG',false); define('CATEGORY_UNKNOWN_ID', -1); /* MySQL data /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ include_once('mysql.php'); include_once('../includes/configure.php'); class LiveStoreProductsImporter { public $minimum_number_of_products_active, $parent_category; function __construct ($since = '') { $this->get_puckator_configuration(); } //Gets the minimum number of products to be active function get_puckator_configuration() { global $db; $sql = "SELECT configuration_value, configuration_key FROM configuration WHERE configuration_group_id=1500"; if (!$live_result = $db->sql_query($sql)) { $this->report('[sql failure] ' . $sql . '\r\n' . $db->sql_error($live_result)); } elseif (DEBUG) { $this->report('[sql ok] ' . $sql); } while ($row = $db->sql_fetchrow($live_result)) { if ($row['configuration_key'] == "MINIMUM_NUMBER_OF_PRODUCTS_ACTIVE") { $this->minimum_number_of_products_active = $row['configuration_value']; } elseif ($row['configuration_key'] == "PARENT_CATEGORY") { $this->parent_category = $row['configuration_value']; } } } public function report ($message) { echo "<p style='font-size:10px;font-family:Verdana;color:navy'>$message</p>"; } //Calculates net prices static function get_net_price ($supplier_price, $delivery_fee = 0) { return (float)$supplier_price; } //Rounds price to .49 or .99 static function round_price ($price) { if ($price < 0.75) return 0.49; $price_int = floor((float)$price); $price_dec = (float)$price - (float)$price_int; if ($price_dec < 0.25) { return (float)$price_int - 0.01; } elseif ($price_dec < 0.75) { return (float)$price_int + 0.49; } else { return (float)$price_int + 0.99; } } function GetParentCategoryId($supplier_cat_id) { global $db; $sql = "SELECT parent_id FROM puck_categories where supplier_cat_id = $supplier_cat_id"; if (!$puck_result = $db->sql_query($sql)) { $this->report('[sql failure] ' . $sql . '\r\n' . $db->sql_error($live_result)); } elseif (DEBUG) { $this->report('[sql ok] ' . $sql); } if ($row = $db->sql_fetchrow($puck_result)) { $parent_id = $row['parent_id']; $sql = "SELECT supplier_cat_id FROM puck_categories where categories_id = $parent_id"; if (!$puck_result = $db->sql_query($sql)) { $this->report('[sql failure] ' . $sql . '\r\n' . $db->sql_error($live_result)); } elseif (DEBUG) { $this->report('[sql ok] ' . $sql); } if ($row = $db->sql_fetchrow($puck_result)) { $supplier_parent_cat_id = $row['supplier_cat_id']; $parent_id = $this->GetCategoryID($supplier_parent_cat_id); return $parent_id?$parent_id:CATEGORY_UNKNOWN_ID; } } } function GetTopCategoryId() { if (empty($this->parent_category)) { return 0; } global $db; $sql = "SELECT categories_id FROM categories_description where categories_name like '{$this->parent_category}'"; if (!$result = $db->sql_query($sql)) { $this->report('[sql failure] ' . $sql . '\r\n' . $db->sql_error($result)); } elseif (DEBUG) { $this->report('[sql ok] ' . $sql); } if ($row = $db->sql_fetchrow($result)) { return $row['categories_id']; } else { $sql = "INSERT INTO categories (parent_id, date_added) VALUES(0, NOW())"; if (!$result = $db->sql_query($sql)) { $this->report('[sql failure] ' . $sql . '\r\n' . $db->sql_error($result)); } elseif (DEBUG) { $this->report('[sql ok] ' . $sql); } if (!$parent_category_id = $db->sql_nextid()) { $this->report("[sql failure] No category id returned for $sql, although the query was successful."); die(); } $sql = "REPLACE INTO categories_description (categories_id, language_id, categories_name) VALUES ($parent_category_id, " . LANGUAGE_ID . ", '{$this->parent_category}')"; if (!$result = $db->sql_query($sql)) { $this->report('[sql failure] ' . $sql . '\r\n' . $db->sql_error($result)); } elseif (DEBUG) { $this->report('[sql ok] ' . $sql); } return $parent_category_id; } } public function GetCategoryID ($supplier_cat_id) { global $db; $sql = "SELECT categories_id FROM categories WHERE supplier_code = '" . SUPPLIER_CODE . "' AND supplier_cat_id = $supplier_cat_id"; if (!$result = $db->sql_query($sql)) { $this->report('[sql failure] ' . $sql); return; } elseif (DEBUG) { $this->report('[sql ok] ' . $sql); } $row = $db->sql_fetchrow($result); return $row['categories_id']; } public function GetProductID ($pid) { global $db; $sql = "SELECT products_id FROM products WHERE products_model = '$pid'"; if (!$result = $db->sql_query($sql)) { $this->report('[sql failure] ' . $sql); return; } elseif (DEBUG) { $this->report('[sql ok] ' . $sql); } $row = $db->sql_fetchrow($result); return $row['products_id']; } function ImportProductsToCategories() { global $db; $sql = "SELECT products_id, categories_id FROM puck_products_to_categories"; if (!$result = $db->sql_query($sql)) { $this->report('[sql failure] ' . $sql . '\r\n' . $db->sql_error($result)); } elseif (DEBUG) { $this->report('[sql ok] ' . $sql); } while ($row = $db->sql_fetchrow($result)) { $products_id = $row['products_id']; $categories_id = $row['categories_id']; $sql = "SELECT products_model FROM puck_products WHERE products_id = $products_id"; if (!$puck_result = $db->sql_query($sql)) { $this->report('[sql failure] ' . $sql . '\r\n' . $db->sql_error($puck_result)); } elseif (DEBUG) { $this->report('[sql ok] ' . $sql); } $row = $db->sql_fetchrow($puck_result); $pid = $row['products_model']; $pro_id = $this->GetProductId($pid); $sql = "SELECT supplier_cat_id FROM puck_categories WHERE categories_id = $categories_id"; if (!$puck_result = $db->sql_query($sql)) { $this->report('[sql failure] ' . $sql . '\r\n' . $db->sql_error($puck_result)); } elseif (DEBUG) { $this->report('[sql ok] ' . $sql); } $row = $db->sql_fetchrow($puck_result); $supplier_cat_id = $row['supplier_cat_id']; $cat_id = $this->GetCategoryID($supplier_cat_id); $sql = "REPLACE INTO products_to_categories (products_id, categories_id) VALUES ($pro_id, $cat_id)"; if (!$live_result = $db->sql_query($sql)) { $this->report('[sql failure] ' . $sql . '\r\n' . $db->sql_error($live_result)); } elseif (DEBUG) { $this->report('[sql ok] ' . $sql); } } } function ImportProducts () { global $db; $sql = "SELECT products_id FROM puck_products"; if (!$result = $db->sql_query($sql)) { $this->report('[sql failure] ' . $sql . '\r\n' . $db->sql_error($result)); } elseif (DEBUG) { $this->report('[sql ok] ' . $sql); } while ($row = $db->sql_fetchrow($result)) { $products_id = $row['products_id']; $this->ImportProduct($products_id); } } function ImportProduct ($id) { global $db, $numberOfProductsInactive; //Retrieves all the products data from puck table $sql = "SELECT products_model, products_id, products_quantity, products_image, products_price, products_date_added, products_weight, products_status, manufacturers_id FROM puck_products where products_id = $id"; $result = $db->sql_query($sql); if ($row = $db->sql_fetchrow($result)) { $pid = $row['products_model']; $sql = "SELECT products_id, products_status FROM products WHERE products_model = '$pid'"; if (!$live_result = $db->sql_query($sql)) { $this->report('[sql failure] ' . $sql . '\r\n' . $db->sql_error($live_result)); } elseif (DEBUG) { $this->report('[sql ok] ' . $sql); } $price = $this->get_net_price($this->GetProductIncreasedPrice($id, $row['products_price'])); $stock = intval($row['products_quantity']); $image = $row['products_image']; $weight = ''; //TODO: $manufacturer_id = $row['manufacturers_id']; $products_id = $row['products_id']; if ($stock < $this->minimum_number_of_products_active) { $status = 0; $numberOfProductsInactive++; } else { $status = 1; } if (!$row = $db->sql_fetchrow($live_result)) { //Insert into live products table $sql = "INSERT INTO products (products_model, products_quantity, products_image, products_price, products_date_added, products_weight, products_status, manufacturers_id) VALUES ('$pid', $stock, '$image', $price, NOW(), '$weight', $status, '$manufacturer_id')"; if (!$live_result = $db->sql_query($sql)) { $this->report('[sql failure] ' . $sql . '\r\n' . $db->sql_error($live_result)); } elseif (DEBUG) { $this->report('[sql ok] ' . $sql); } if (!$product_id = $db->sql_nextid()) { $this->report("[sql failure] No product id returned for $sql, although the query was successful."); } } else { //Updates products $product_id = $row['products_id']; $sql = "UPDATE products SET products_quantity = $stock, products_image = '$image', products_price = $price, products_last_modified = NOW(), products_weight = '$weight', manufacturers_id = '$manufacturer_id', products_status = $status WHERE products_id = $product_id; "; if (!$live_result = $db->sql_query($sql)) { $this->report('[sql failure] ' . $sql . '\r\n' . $db->sql_error($live_result)); } elseif (DEBUG) { $this->report('[sql ok] ' . $sql); } } //Import data in products_description table $sql = "SELECT products_id, language_id, products_name, products_description FROM puck_products_description WHERE products_id = $products_id AND language_id = " . LANGUAGE_ID; if (!$puck_result = $db->sql_query($sql)) { $this->report('[sql failure] ' . $sql . '\r\n' . $db->sql_error($puck_result)); } elseif (DEBUG) { $this->report('[sql ok] ' . $sql); } $row = $db->sql_fetchrow($puck_result); $lang = $row['language_id']; $name = $db->sql_escape($row['products_name']); $description = $db->sql_escape($row['products_description']); $sql = "SELECT products_id FROM products_description WHERE products_id = $product_id AND language_id = " . LANGUAGE_ID; if (!$live_result = $db->sql_query($sql)) { $this->report('[sql failure] ' . $sql . '\r\n' . $db->sql_error($live_result)); } elseif (DEBUG) { $this->report('[sql ok] ' . $sql); } if (!$row = $db->sql_fetchrow($live_result)) { //New product $sql = "INSERT INTO products_description (products_id, language_id, products_name, products_description) VALUES ($product_id, $lang, '$name', '$description')"; if (!$live_result = $db->sql_query($sql)) { $this->report('[sql failure] ' . $sql . '\r\n' . $db->sql_error($live_result)); } elseif (DEBUG) { $this->report('[sql ok] ' . $sql); } else { $this->report("[$name] - Updated"); } if (!$products_id = $db->sql_nextid()) { $this->report("[sql failure] No product id returned for $sql, although the query was successful."); return; } } else { //Updates products description $sql = "UPDATE products_description SET products_name = '$name', products_description = '$description' WHERE products_id = $product_id AND language_id = $lang"; if (!$live_result = $db->sql_query($sql)) { $this->report('[sql failure] ' . $sql . '\r\n' . $db->sql_error($live_result)); } elseif (DEBUG) { $this->report('[sql ok] ' . $sql); } else { $this->report("[$name] - Updated"); } } $sql = "DELETE FROM products_attributes WHERE products_id = $product_id"; if (!$db->sql_query($sql)) { $this->report('[sql failure] ' . $sql); } elseif (DEBUG) { $this->report('[sql ok] ' . $sql); } $sql = "SELECT products_attributes_id, products_id, options_id, options_values_id, options_values_price, price_prefix FROM puck_products_attributes WHERE products_id = $id ORDER BY products_id, options_id"; if (!$puck_result = $db->sql_query($sql)) { $this->report('[sql failure] ' . $sql . '\r\n' . $db->sql_error($puck_result)); } elseif (DEBUG) { $this->report('[sql ok] ' . $sql); } $puck_options_id = 0; $options_id = 1; while ($row = $db->sql_fetchrow($puck_result)) { if ($row['options_id'] != $puck_options_id) { $options_id = $this->ImportProductOption($row['options_id']); $puck_options_id = $row['options_id']; } $options_values_id = $this->ImportProductOptionsValue($row['options_values_id']); //echo $options_values_id; //echo $options_id; $sql = "REPLACE INTO products_options_values_to_products_options(products_options_id, products_options_values_id) VALUES ($options_id, $options_values_id)"; if (!$db->sql_query($sql)) { $this->report('<b><u>[sql failure] ' . $sql . '</u></b>'); } elseif (DEBUG) { $this->report('[sql ok] ' . $sql); } $sql = "INSERT INTO products_attributes(products_id, options_id, options_values_id, options_values_price, price_prefix) VALUES ($product_id, $options_id, $options_values_id, 0, '+')"; if (!$live_result = $db->sql_query($sql)) { $this->report('<b><u>[sql failure] ' . $sql . '\r\n' . $db->sql_error($live_result) . '</u></b>'); } elseif (DEBUG) { $this->report('[sql ok] ' . $sql); } } } } function ImportCategories () { global $db; $sql = "SELECT categories_id FROM puck_categories"; if (!$result = $db->sql_query($sql)) { $this->report('[sql failure] ' . $sql . '\r\n' . $db->sql_error($result)); } elseif (DEBUG) { $this->report('[sql ok] ' . $sql); } while ($row = $db->sql_fetchrow($result)) { $categories_id = $row['categories_id']; $this->ImportCategory($categories_id); } } //Fix parent categories not yet known during parsing, not public, ... public function FixCategories() { global $db; $sql = "SELECT categories_id, supplier_cat_id FROM categories WHERE parent_id = " . CATEGORY_UNKNOWN_ID . " AND supplier_code LIKE '" . SUPPLIER_CODE . "'"; if (!$result = $db->sql_query($sql)) { $this->report('[sql failure] ' . $sql . '\r\n' . $db->sql_error($result)); } elseif (DEBUG) { $this->report('[sql ok] ' . $sql); } while ($row = $db->sql_fetchrow($result)) { //Gets the supplier parent cat id $parent_cat_id = $this->GetParentCategoryID($row['supplier_cat_id']); $sql = "UPDATE categories SET parent_id = $parent_cat_id WHERE categories_id = {$row['categories_id']}"; $db->sql_query($sql); } } function ImportCategory ($id) { global $db; $sql = "SELECT categories_id, categories_image, parent_id, supplier_code, supplier_cat_id FROM puck_categories WHERE categories_id = $id"; if (!$result = $db->sql_query($sql)) { $this->report('[sql failure] ' . $sql . '\r\n' . $db->sql_error($result)); } elseif (DEBUG) { $this->report('[sql ok] ' . $sql); } if ($row = $db->sql_fetchrow($puck_result)) { $this->parent_category = $this->GetTopCategoryId(); $categories_id = $row['categories_id']; $categories_image = $row['supplier_cat_id']; $parent_id = $row['parent_id']==0?$this->parent_category:$this->GetParentCategoryId($row['supplier_cat_id']); $supplier_code = $row['supplier_code']; $supplier_cat_id = $row['supplier_cat_id']; if (!$cat_id = $this->GetCategoryID($supplier_cat_id)) { $sql = "INSERT INTO categories (categories_image, parent_id, date_added, supplier_code, supplier_cat_id) VALUES ('$categories_image', $parent_id, NOW(), '$supplier_code', $supplier_cat_id)"; if (!$live_result = $db->sql_query($sql)) { $this->report('[sql failure] ' . $sql . '\r\n' . $db->sql_error($live_result)); } elseif (DEBUG) { $this->report('[sql ok] ' . $sql); } if (!$cat_id = $db->sql_nextid()) { $this->report("[sql failure] No category id returned for $sql, although the query was successful."); return; } } else { $sql = "UPDATE categories SET categories_image = '$categories_image', parent_id = $parent_id, last_modified = NOW(), supplier_code = '$supplier_code', supplier_cat_id = $supplier_cat_id WHERE categories_id = $cat_id"; if (!$live_result = $db->sql_query($sql)) { $this->report('[sql failure] ' . $sql . '\r\n' . $db->sql_error($live_result)); } elseif (DEBUG) { $this->report('[sql ok] ' . $sql); } } $sql = "SELECT categories_name, language_id FROM puck_categories_description WHERE categories_id = $categories_id"; if (!$puck_result = $db->sql_query($sql)) { $this->report('[sql failure] ' . $sql . '\r\n' . $db->sql_error($puck_result)); } elseif (DEBUG) { $this->report('[sql ok] ' . $sql); } if ($row = $db->sql_fetchrow($puck_result)) { $categories_name = $row['categories_name']; $lang = $row['language_id']; $sql = "REPLACE INTO categories_description(categories_id, language_id, categories_name) VALUES ($cat_id, $lang, '$categories_name')"; if (!$live_result = $db->sql_query($sql)) { $this->report('[sql failure] ' . $sql . '\r\n' . $db->sql_error($live_result)); } elseif (DEBUG) { $this->report('[sql ok] ' . $sql); } else { $this->report("[$categories_name] - Updated"); } } } } function GetProductIncreasedPrice($id, $price) { global $db; $puck_result = $db->sql_query("SELECT c.price_increase FROM puck_products_to_categories as p JOIN puck_categories as c ON p.categories_id = c.categories_id WHERE p.products_id = $id"); $row = $db->sql_fetchrow($result); $price_increase = $row['price_increase']?$row['price_increase']:0; return floatval($price)/100*(100+floatval($price_increase)); } function ImportProductOptionsValue($id) { global $db; //Insert product options values $sql = "SELECT language_id, products_options_values_name FROM puck_products_options_values WHERE products_options_values_id = $id"; if (!$puck_result = $db->sql_query($sql)) { $this->report('[sql failure] ' . $sql . '\r\n' . $db->sql_error($puck_result)); return; } elseif (DEBUG) { $this->report('[sql ok] ' . $sql); } if ($row = $db->sql_fetchrow($puck_result)) { $products_options_values_name = $row['products_options_values_name']; $lang = $row['language_id']; $products_options_values_id = $row['products_options_values_id']; $sql = "SELECT language_id, products_options_values_id, products_options_values_name FROM products_options_values where products_options_values_name LIKE '$products_options_values_name'"; if (!$live_result = $db->sql_query($sql)) { $this->report('[sql failure] ' . $sql . '\r\n' . $db->sql_error($live_result)); return; } elseif (DEBUG) { //$this->report('[sql ok] ' . $sql); } if ($row = $db->sql_fetchrow($live_result)) { return $row['products_options_values_id']; } else { $sql = "INSERT INTO products_options_values(language_id, products_options_values_id, products_options_values_name) VALUES ('$lang', '$products_options_values_id', '$products_options_values_name')"; if (!$live_result = $db->sql_query($sql)) { $this->report('<b><u>[sql failure] ' . $sql . '\r\n' . $db->sql_error($live_result) . '</u></b>'); return false; } elseif (DEBUG) { $this->report('[sql ok] ' . $sql); } if (!$products_options_values_id = $db->sql_nextid()) { $this->report("[sql failure] No products options values id returned for $sql, although the query was successful."); return false; } return $products_options_values_id; } } } function ImportProductOption($id) { //Insert product options global $db; $sql = "SELECT language_id, products_options_name FROM puck_products_options WHERE products_options_id = $id"; if (!$puck_result = $db->sql_query($sql)) { $this->report('[sql failure] ' . $sql . '\r\n' . $db->sql_error($puck_result)); return; } elseif (DEBUG) { $this->report('[sql ok] ' . $sql); } if ($row = $db->sql_fetchrow($puck_result)) { $products_options_name = $row['products_options_name']; $lang = $row['language_id']; $sql = "SELECT language_id, products_options_id FROM products_options WHERE products_options_name LIKE '$products_options_name'"; if (!$live_result = $db->sql_query($sql)) { $this->report('[sql failure] ' . $sql . '\r\n' . $db->sql_error($live_result)); return; } elseif (DEBUG) { $this->report('[sql ok] ' . $sql); } if ($row = $db->sql_fetchrow($live_result)) { return $row['products_options_id']; } else { $sql = "INSERT INTO products_options(language_id, products_options_name) VALUES ('$lang', '$products_options_name')"; if (!$live_result = $db->sql_query($sql)) { $this->report('[sql failure] ' . $sql . '\r\n' . $db->sql_error($live_result)); return false; } elseif (DEBUG) { $this->report('[sql ok] ' . $sql); } if (!$products_options_id = $db->sql_nextid()) { $this->report("[sql failure] No products options id returned for $sql, although the query was successful."); return false; } return $products_options_id; } } } function ImportFromPuckTables () { $this->ImportCategories(); $this->FixCategories(); $this->ImportProducts(); $this->ImportProductsToCategories(); } } $db = new sql_db(DB_SERVER, DB_SERVER_USERNAME, DB_SERVER_PASSWORD, DB_DATABASE, false); if (!$db->db_connect_id) { die(mysql_error()); } echo <<<PAGE <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Puckator Importer</title> <script src="scripts/categories.js" language="javascript" type="text/javascript"></script> <link href="styles/style.css" rel="stylesheet" type="text/css"/> </head> <body> <table cellpadding="0" cellspacing="0" width="100%"> <tr><td align="center"><img src="images/puckator_live_update.gif" alt="Puckator Logo"></td></tr> <tr> <td> </td> </tr> <tr><td align="center"> <div id="divLoading"> <table cellpadding="0" cellspacing="0" width="100%"> <tr> <td valign="middle" align="center"> <img src="images/loading.gif" alt="Loading..."> </td> </tr> <tr> <td valign="middle" style="text-align: center;" class="report_header">Please wait as this may take a while depending on how many categories you have selected to import.</td> </tr> </table> </div> </td></tr> </table> <table cellpadding="0" cellspacing="0" width="100%"> <tr><td align="center"> PAGE; $numberOfProductsInactive = 0; $livestoreImporter = new LiveStoreProductsImporter(); $livestoreImporter->ImportFromPuckTables(); echo <<<PAGE <table cellpadding="0" cellspacing="0" width="400px"> <tr> <td class="report_header" colspan="2" style="text-align:center;">Update Live Store Report</td> </tr> <tr> <td class="report_field">Number Of Products Inactive:</td> <td class="report_value">$numberOfProductsInactive</td> </tr> </table> <table cellpadding="0" cellspacing="0" width="400px"> <tr> <td> </td> </tr> <tr> <td> <div class="buttons"> <button type="button" class="positive" onclick="document.location.href='../puck_categories.php'"><img src="images/return_in.gif" alt="Click here to go to the admin."/> Back To Admin </button> </div> </td> </tr> </table> </td></tr> </table> <script language="javascript" type="text/javascript"> document.getElementById("divLoading").innerHTML=""; </script> </body> </html> PAGE; ?>[/code] Many Thanks AN Quote Link to comment https://forums.phpfreaks.com/topic/191239-help-required-with-debugging-script/ Share on other sites More sharing options...
JAY6390 Posted February 7, 2010 Share Posted February 7, 2010 Could you narrow down where the code is that creates the queries? That's quite a lot of code to have a "quick look" over Quote Link to comment https://forums.phpfreaks.com/topic/191239-help-required-with-debugging-script/#findComment-1008327 Share on other sites More sharing options...
anothernut Posted February 7, 2010 Author Share Posted February 7, 2010 Ok sorry I hope I have got it all here lol function ImportProductOptionsValue($id) { global $db; //Insert product options values $sql = "SELECT language_id, products_options_values_name FROM puck_products_options_values WHERE products_options_values_id = $id"; if (!$puck_result = $db->sql_query($sql)) { $this->report('[sql failure] ' . $sql . '\r\n' . $db->sql_error($puck_result)); return; } elseif (DEBUG) { $this->report('[sql ok] ' . $sql); } if ($row = $db->sql_fetchrow($puck_result)) { $products_options_values_name = $row['products_options_values_name']; $lang = $row['language_id']; $products_options_values_id = $row['products_options_values_id']; $sql = "SELECT language_id, products_options_values_id, products_options_values_name FROM products_options_values where products_options_values_name LIKE '$products_options_values_name'"; if (!$live_result = $db->sql_query($sql)) { $this->report('[sql failure] ' . $sql . '\r\n' . $db->sql_error($live_result)); return; } elseif (DEBUG) { //$this->report('[sql ok] ' . $sql); } if ($row = $db->sql_fetchrow($live_result)) { return $row['products_options_values_id']; } else { $sql = "INSERT INTO products_options_values(language_id, products_options_values_id, products_options_values_name) VALUES ('$lang', '$products_options_values_id', '$products_options_values_name')"; if (!$live_result = $db->sql_query($sql)) { $this->report('<b><u>[sql failure] ' . $sql . '\r\n' . $db->sql_error($live_result) . '</u></b>'); return false; } elseif (DEBUG) { $this->report('[sql ok] ' . $sql); } if (!$products_options_values_id = $db->sql_nextid()) { $this->report("[sql failure] No products options values id returned for $sql, although the query was successful."); return false; } return $products_options_values_id; } } } function ImportProductOption($id) { //Insert product options global $db; $sql = "SELECT language_id, products_options_name FROM puck_products_options WHERE products_options_id = $id"; if (!$puck_result = $db->sql_query($sql)) { $this->report('[sql failure] ' . $sql . '\r\n' . $db->sql_error($puck_result)); return; } elseif (DEBUG) { $this->report('[sql ok] ' . $sql); } if ($row = $db->sql_fetchrow($puck_result)) { $products_options_name = $row['products_options_name']; $lang = $row['language_id']; $sql = "SELECT language_id, products_options_id FROM products_options WHERE products_options_name LIKE '$products_options_name'"; if (!$live_result = $db->sql_query($sql)) { $this->report('[sql failure] ' . $sql . '\r\n' . $db->sql_error($live_result)); return; } elseif (DEBUG) { $this->report('[sql ok] ' . $sql); } if ($row = $db->sql_fetchrow($live_result)) { return $row['products_options_id']; } else { $sql = "INSERT INTO products_options(language_id, products_options_name) VALUES ('$lang', '$products_options_name')"; if (!$live_result = $db->sql_query($sql)) { $this->report('[sql failure] ' . $sql . '\r\n' . $db->sql_error($live_result)); return false; } elseif (DEBUG) { $this->report('[sql ok] ' . $sql); } if (!$products_options_id = $db->sql_nextid()) { $this->report("[sql failure] No products options id returned for $sql, although the query was successful."); return false; } return $products_options_id; } } } Thanks AN Quote Link to comment https://forums.phpfreaks.com/topic/191239-help-required-with-debugging-script/#findComment-1008328 Share on other sites More sharing options...
jl5501 Posted February 7, 2010 Share Posted February 7, 2010 Your errors all seem to be from insert queries, where you seem to be expecting to get data from An insert or an update query does not return a result set, only the number of rows affected. On your error line you would be better off showing the results of mysql_error() to show the error mesage from mysql. Quote Link to comment https://forums.phpfreaks.com/topic/191239-help-required-with-debugging-script/#findComment-1008334 Share on other sites More sharing options...
anothernut Posted February 7, 2010 Author Share Posted February 7, 2010 Your errors all seem to be from insert queries, where you seem to be expecting to get data from An insert or an update query does not return a result set, only the number of rows affected. On your error line you would be better off showing the results of mysql_error() to show the error mesage from mysql. Sorry I am not quite sure what you mean, would you please give me an example. Thanks AN Quote Link to comment https://forums.phpfreaks.com/topic/191239-help-required-with-debugging-script/#findComment-1008335 Share on other sites More sharing options...
jl5501 Posted February 7, 2010 Share Posted February 7, 2010 Actually, you have a call to a function mysql_error in your db class which you are using in your error messages, and I would expect this to eventually call the mysql_error() function, in which case, you should see the error(s) if any being reported. If you are not seeing errors, then it is likely that the queries themselves are ok and doing the inserts but maybe not with the correct data. You will need to show the current database values after the insert, either by another select after, or by having a look in phpmyadmin to see what has been added to the db Quote Link to comment https://forums.phpfreaks.com/topic/191239-help-required-with-debugging-script/#findComment-1008343 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.