SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru
    Join Date
    Oct 2011
    Posts
    658
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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:

    PHP 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 == $ETD $cell->nodeValue;  
                      if ( 
    $index == $PO_No $cell->nodeValue;
                      if ( 
    $index == $SKUCode $cell->nodeValue;
                      if ( 
    $index == $Description $cell->nodeValue;
                      if ( 
    $index == $POReq $cell->nodeValue;
                      if ( 
    $index == $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. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,341
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    have you tested your query outside of php?

    more specifically, how do you know that an INSERT statement with a VALUES clause can also take a WHERE clause?

    hint: it can't
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Guru
    Join Date
    Oct 2011
    Posts
    658
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937 View Post
    have you tested your query outside of php?

    more specifically, how do you know that an INSERT statement with a VALUES clause can also take a WHERE clause?

    hint: it can't
    I just tried it


Bookmarks

Posting Permissions

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