Colton.Wagner Posted October 10, 2009 Share Posted October 10, 2009 I get an xml feed every thirty minutes and im try to take it and match the part numbers then update the quantities here is what I have so far. Can anyone help? <?php session_start(); $_SESSION['parts'] = array(); error_reporting(E_ALL); ?> <html> <head> <link rel="shortcut icon" href="/favicon.ico" /> <title> </title> </head> <body> <?php mysql_connect(""); mysql_select_db('products'); $parser = xml_parser_create(); function start($parser, $element_name, $element_attrs) { switch($element_name) { case "SKU": // this is the start of a set of data $_SESSION['parts'] = array(); // create an empty set break; case "TIME": $query = sprintf("UPDATE products SET products_quantity = $quantity WHERE products_model = $part"); mysql_query($query); break; default: } } function stop($parser, $element_name) { } function char($parser,$data) { $data = trim($data); if($data != ''){ if(!isset($_SESSION['parts']['SKU'])){ $_SESSION['parts']['SKU'] = $data; } elseif (!isset($_SESSION['parts']['QTY'])){ $_SESSION['parts']['QTY'] = $data; } elseif (!isset($_SESSION['parts']['PART'])){ $_SESSION['parts']['PART'] = $data; } } } xml_set_element_handler($parser, "start", "stop"); xml_set_character_data_handler($parser, "char"); $fp=fopen("","r"); while ($data=fread($fp,4096)) { xml_parse($parser,$data,feof($fp)) or die (sprintf("XML Error: %s at line %d", xml_error_string(xml_get_error_code($parser)), xml_get_current_line_number($parser))); } xml_parser_free($parser); $quantity = ($_SESSION['parts']['QTY']); $part = ($_SESSION['parts']['PART']); ?> </body> </html> The error is this: Notice: Undefined variable: quantity in on line 31 Notice: Undefined variable: part in on line 31 I'm getting this error because you can't make a variable out of a $_SESSION array. Link to comment https://forums.phpfreaks.com/topic/177210-solved-updating-quantities-via-xml/ Share on other sites More sharing options...
Colton.Wagner Posted October 10, 2009 Author Share Posted October 10, 2009 Bump Link to comment https://forums.phpfreaks.com/topic/177210-solved-updating-quantities-via-xml/#findComment-934423 Share on other sites More sharing options...
xenophobia Posted October 10, 2009 Share Posted October 10, 2009 As the error message shown, you having an undefined variable used on line 31 which is: $query = sprintf("UPDATE products SET products_quantity = $quantity WHERE products_model = $part"); The one inside your string. I don't know what you wish to achieve, but you must declare the variable $quantity before you using them. Also the $part. Link to comment https://forums.phpfreaks.com/topic/177210-solved-updating-quantities-via-xml/#findComment-934432 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.