Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Aug 2010
    Posts
    713
    Thanks
    165
    Thanked 0 Times in 0 Posts

    Insert only date where month is not previous month

    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 = date

    Actually 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:

    Code:
    <?php
    error_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:

    Code:
    $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

  • #2
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,634
    Thanks
    4
    Thanked 148 Times in 139 Posts
    you can't have a WHERE clause in an INSERT.

  • #3
    Regular Coder
    Join Date
    Aug 2010
    Posts
    713
    Thanks
    165
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by guelphdad View Post
    you can't have a WHERE clause in an INSERT.
    So what would be the possible thing should I do?

    Thank you


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •