Jump to content

Updating Quanties by Checking the product Sku


Colton.Wagner

Recommended Posts

So I am trying to use an xml file to update a products quantity by checking the product id then updating it in the database.

 

<?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);
   $quantity = trim($quantity);
   $part = trim($part);
   if($data != ''){
      if(!isset($_SESSION['parts']['SKU'])){
         $_SESSION['parts']['SKU'] = $data;
      } elseif (!isset($_SESSION['parts']['QTY'])){
         $_SESSION['parts']['QTY'] = $quantity;
      } elseif (!isset($_SESSION['parts']['PART'])){
         $_SESSION['parts']['PART'] = $part;
      }
   }
}

xml_set_element_handler($parser, "start", "stop");
xml_set_character_data_handler($parser, "char");

$fp=fopen("http://morris.morriscostumes.com/out/available_batchnynyy_001.xml","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>

 

I get this error:

 

Notice: Undefined variable: quantity in  on line 45

Notice: Undefined variable: part in on line 46

Undefined variable is not an error perse it's a notice, it's basically telling you that your using a variable that at no point have you assigned a value, meaning it doesn't exist (so will have a null value). At a glance I'm guessing lines 45 and 46 are these two...

 

$quantity = trim($quantity);
$part = trim($part);

 

Your setting $quantity and $part equal to a trimmed version of themselves. But at no point before that line do you assign either variable a value, meaning that you are essentially trying to trim an empty value.

No it doesn't. You start with a null variable then try and trim it, then store it in the $_SESSION array. At no point in the code do you assign a true value to $quantity.

 

   $data = trim($data);
   $quantity = trim($quantity);
   $part = trim($part);
   if($data != ''){
      if(!isset($_SESSION['parts']['SKU'])){
         $_SESSION['parts']['SKU'] = $data;
      } elseif (!isset($_SESSION['parts']['QTY'])){
         $_SESSION['parts']['QTY'] = $quantity;
      } elseif (!isset($_SESSION['parts']['PART'])){
         $_SESSION['parts']['PART'] = $part;
      }
   }

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.