Colton.Wagner Posted October 8, 2009 Share Posted October 8, 2009 I have made an xml quantity uploading script here it doesnt seem to update the quantity can you tell me what im doing wrong? <?php session_start(); $_SESSION['parts'] = array(); error_reporting(E_ALL); ?> <html> <head> <link rel="shortcut icon" href="/favicon.ico" /> <title> TItle of the website </title> </head> <body> <?php mysql_connect(''); mysql_select_db('products'); $parser = xml_parser_create(); $quantity = ($_SESSION['parts']['QTY']); $part = ($_SESSION['parts']['PART']); 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("xml filename","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); ?> </body> </html> The error is as follows: Notice: Undefined index: QTY in on line 22 Notice: Undefined index: PART in on line 23 Notice: Undefined variable: quantity in on line 34 Notice: Undefined variable: part in on line 34 Notice: Undefined variable: quantity in on line 34 Notice: Undefined variable: part in on line 34 That goes on for days Quote Link to comment https://forums.phpfreaks.com/topic/177010-solved-updating-a-quantity-by-checking-the-product_model/ Share on other sites More sharing options...
Colton.Wagner Posted October 8, 2009 Author Share Posted October 8, 2009 bump Quote Link to comment https://forums.phpfreaks.com/topic/177010-solved-updating-a-quantity-by-checking-the-product_model/#findComment-933329 Share on other sites More sharing options...
mikesta707 Posted October 8, 2009 Share Posted October 8, 2009 that means that you are using variables that you haven't defined yet. Either you misstyped the variable names, or you need to define them.. Quote Link to comment https://forums.phpfreaks.com/topic/177010-solved-updating-a-quantity-by-checking-the-product_model/#findComment-933333 Share on other sites More sharing options...
ToonMariner Posted October 8, 2009 Share Posted October 8, 2009 its very simple - you have $_SESSION['parts'] = array(); this sets that session variable to an empty array. Between that line and the first attempt to access the QTY element of a non existent array there is no code to populate the parts array. Quote Link to comment https://forums.phpfreaks.com/topic/177010-solved-updating-a-quantity-by-checking-the-product_model/#findComment-933338 Share on other sites More sharing options...
Colton.Wagner Posted October 9, 2009 Author Share Posted October 9, 2009 that means that you are using variables that you haven't defined yet. Either you misstyped the variable names, or you need to define them.. They are for sure not miss typed they have been defined but they are not being parsed in correctly because I don't know how to correctly process the syntax to do it. Quote Link to comment https://forums.phpfreaks.com/topic/177010-solved-updating-a-quantity-by-checking-the-product_model/#findComment-933488 Share on other sites More sharing options...
Colton.Wagner Posted October 9, 2009 Author Share Posted October 9, 2009 that means that you are using variables that you haven't defined yet. Either you misstyped the variable names, or you need to define them.. They are for sure not miss typed they have been defined but they are not being parsed in correctly because I don't know how to correctly process the syntax to do it. The way i have that set up is it parse's the xml into the $_SESSION['parts']['wty'] then it sets that equal to the variable $quanitity then updates that into the database im not so sure that i am using the correct syntax for that. Quote Link to comment https://forums.phpfreaks.com/topic/177010-solved-updating-a-quantity-by-checking-the-product_model/#findComment-933506 Share on other sites More sharing options...
Philip Posted October 9, 2009 Share Posted October 9, 2009 its very simple - you have $_SESSION['parts'] = array(); this sets that session variable to an empty array. Between that line and the first attempt to access the QTY element of a non existent array there is no code to populate the parts array. Toon is right, <?php session_start(); $_SESSION['parts'] = array(); error_reporting(E_ALL); ?> ... html here.... <?php mysql_connect(''); mysql_select_db('products'); $parser = xml_parser_create(); // The following are causing problems: $quantity = ($_SESSION['parts']['QTY']); $part = ($_SESSION['parts']['PART']); Quote Link to comment https://forums.phpfreaks.com/topic/177010-solved-updating-a-quantity-by-checking-the-product_model/#findComment-933508 Share on other sites More sharing options...
Colton.Wagner Posted October 9, 2009 Author Share Posted October 9, 2009 I see why it isn't working I just don't know how to fix it. I need it to check for those variables after it parses the xml or else it wont work. Is there another way to update the fields via xml parsing? Quote Link to comment https://forums.phpfreaks.com/topic/177010-solved-updating-a-quantity-by-checking-the-product_model/#findComment-933514 Share on other sites More sharing options...
Colton.Wagner Posted October 9, 2009 Author Share Posted October 9, 2009 bump Quote Link to comment https://forums.phpfreaks.com/topic/177010-solved-updating-a-quantity-by-checking-the-product_model/#findComment-933752 Share on other sites More sharing options...
Colton.Wagner Posted October 9, 2009 Author Share Posted October 9, 2009 bump Quote Link to comment https://forums.phpfreaks.com/topic/177010-solved-updating-a-quantity-by-checking-the-product_model/#findComment-933842 Share on other sites More sharing options...
ToonMariner Posted October 10, 2009 Share Posted October 10, 2009 if you can see why it doesn't work you will know that you need to assign values to the array held in $_SESSION['parts'] BEFORE you start using them. Quote Link to comment https://forums.phpfreaks.com/topic/177010-solved-updating-a-quantity-by-checking-the-product_model/#findComment-934465 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.