Jump to content

insert only date where month is not the previous month


newphpcoder
 Share

Recommended Posts

Hi...I have codes in uploading .xml file to my database table, now I only need to save or insert only the data where ETD (Month from Date) is not previous Month.ETD = dateActually it's my first time to encounter this and while I'm posting this issue in forums., I also tried to find the answer.here is my code:

<?phperror_reporting(E_ALL ^ E_NOTICE);date_default_timezone_set("Asia/Singapore"); //set the time zone   $data = array();$con = mysql_connect("localhost", "root","");if (!$con) {  die(mysql_error());}$db = mysql_select_db("mes", $con);if (!$db) {  die(mysql_error());}$date_now = date('m');function add_employee($ETD,$PO_No,$SKUCode,$Description,$POReq ,$Comp)  {	  global $data;		   	  $con = mysql_connect("localhost", "root","");	  if (!$con){ die(mysql_error());}	  $db = mysql_select_db("mes", $con);	  if (!$db) {		  die(mysql_error());	  }	  $ETD= $ETD;	  $PO_No = $PO_No;	  $SKUCode = $SKUCode;	  $Description = $Description;	  $POReq = $POReq;	  $Comp = $Comp;		  $sql = "INSERT INTO sales_order (ETD,PO_No,SKUCode,Description,POReq,Comp)	  VALUES	  ('$ETD','$PO_No','$SKUCode','$Description','$POReq','$Comp')	  " or die(mysql_error());	  mysql_query($sql, $con);	 	   $data []= array('ETD'=>$ETD,'PO_No'=>$PO_No,'SKUCode'=>$SKUCode,'Description'=>$Description,'POReq'=>$POReq,'Comp'=>$Comp);}if(empty($_FILES['file']['tmp_name'])){$doc = new DOMDocument();$dom = $doc->load('Sales1.xml');	  $rows = $doc->getElementsByTagName('Row');	  global $last_row;	  $last_row = false;	  $first_row = true;	  foreach ($rows as $row)	  {		  if ( !$first_row )		  {			  $ETD = "";			  $PO_No = "";			  $SKUCode = "";			  $Description = "";			  $POReq = "";			  $Comp = "";			 			  $index = 1;			  $cells = $row->getElementsByTagName( 'Cell' );		 			  foreach( $cells as $cell )			  {				  $ind = $cell->getAttribute( 'Index' );				  if ( $ind != null ) $index = $ind;			 				  if ( $index == 1 ) $ETD = $cell->nodeValue; 				  if ( $index == 2 ) $PO_No = $cell->nodeValue;				  if ( $index == 3 ) $SKUCode = $cell->nodeValue;				  if ( $index == 4 ) $Description = $cell->nodeValue;				  if ( $index == 5 ) $POReq = $cell->nodeValue;				  if ( $index == 6 ) $Comp = $cell->nodeValue;				  $index += 1;			  }			 if ($ETD=='' AND $PO_No=='' AND $SKUCode=='' AND $Description=='' AND $POReq=='' AND $Comp=='') { 				    $last_row = true;			  }	 			  else {				    add_employee($ETD,$PO_No,$SKUCode,$Description, $POReq, $Comp); 			  }	 		  }		  if ($last_row==true) {			  $first_row = true;		  }			  else {			  $first_row = false;		  }	  }  }    ?>

I tried this query:

$sql = "INSERT INTO sales_order (ETD,PO_No,SKUCode,Description,POReq,Comp)	  VALUES	  ('$ETD','$PO_No','$SKUCode','$Description','$POReq','$Comp')	  WHERE $ETD_month != '$date_now'" or die(mysql_error());

but still he get date where ETD(month from date) = March.Thank you so much

Link to comment
Share on other sites

What's your question? Are there any error messages? Also, please limit the code you show as much as possible and don't assume any prior knowledge about your situation if possible.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...