Hi...

I have a problemand I tried to resolved it but still I failed..

I need to add a code in a php file where I'm not the one who code, now I need to add code on that file, and the problem is the one who the owner of code is not here.

I need to add code :

Code:
$sub_lotcode = substr($lotCode, 9, 4);
    
    $sql = "SELECT k.PCODE, k.kanban, p.Compounds, p.Max_Lot 
            FROM kanban_checker k, param_settings p 
        WHERE k.kanban = p.Max_Lot AND k.PCODE = '$sub_lotcode' AND p.Compounds = '$sub_lotcode'";
        $result = mysql_query($sql, $con);
         $total = mysql_num_rows($result);
        if ($total <= 0) {
            notify that PCODE reach the maximum        }
        else{
            echo "continue";
        }
here is the code where I need to add this condition:

Code:
<?php
error_reporting(0);
$con = mysql_connect('localhost', 'root','');

if (!$con) {
    echo 'failed';
    die();
}

mysql_select_db("mes", $con);

$lotCode = mysql_real_escape_string($_GET['normal']);
$lotCodeDownGrade = mysql_real_escape_string($_GET['downgrade']);
$terminalNo = mysql_real_escape_string($_GET['n']);
$downMode = mysql_real_escape_string($_GET['down']);
   

   

if ($terminalNo == "1") {
    
    if ($lotCode != "") {

      
        $sql = "SELECT BARCODE FROM LEGALCODES WHERE BARCODE='$lotCode'";
        $result = mysql_query($sql, $con);
        $total = mysql_num_rows($result);
        if ($total <= 0) {
            echo "X"; // X - for non existent in the mes table
        }
        else {    
            $sql = "SELECT LOT_CODE, TERMINAL_ID, ACTIVE FROM DEPENDENCY WHERE LOT_CODE='$lotCode' AND 
                   TERMINAL_ID='1' AND ACTIVE=TRUE";
            $result = mysql_query($sql, $con);
            $total = mysql_num_rows($result);
            if ($total <= 0) {
                echo "0"; // continue to transact
            }
            else {
     
                $sql    = "SELECT LOT_CODE, TERMINAL_ID, ACTIVE FROM DEPENDENCY WHERE LOT_CODE='$lotCode' AND 
                          ACTIVE=TRUE ORDER BY DATE_ENTRY DESC LIMIT 1";
                
                $result = mysql_query($sql, $con);
                
                $row    = mysql_fetch_array($result);
                $total  = mysql_num_rows($result);
                
          
                echo $row['TERMINAL_ID'] ;             }    
        }
    }
}   
  

elseif ($terminalNo == "4") {
    
    if ($lotCode != "") {
        $sql = "SELECT BARCODE FROM LEGALCODES WHERE BARCODE='$lotCode'";
        $result = mysql_query($sql, $con);
        $total = mysql_num_rows($result);
        
        if ($total <= 0) {
            echo "X"; // X - for non existent in the mes table
        }
        
        else {
  
            if ($downMode == "true") {
                $advanceTerminal = ((integer)($terminalNo) + 1);
                $advanceTerminal = (string)($advanceTerminal);
                
                $preTerminal = ((integer)($terminalNo) - 1);
                $preTerminal = (string)($preTerminal);

       
                $sql = "SELECT LOT_CODE, TERMINAL_ID, ACTIVE FROM DEPENDENCY WHERE LOT_CODE='$lotCode' AND                                              TERMINAL_ID='$advanceTerminal' AND ACTIVE=TRUE";
                       $result = mysql_query($sql, $con);
                       $total = mysql_num_rows($result);
                  
                if ($total <= 0) {
                       
                        $sql = "SELECT LOT_CODE, TERMINAL_ID, ACTIVE FROM DEPENDENCY WHERE LOT_CODE='$lotCode' AND                                              TERMINAL_ID='$preTerminal' AND ACTIVE=TRUE";
                        
                        $result = mysql_query($sql, $con);
                        $total = mysql_num_rows($result);
                        
                        if ($total <= 0) {
                            $sql = "SELECT LOT_CODE, TERMINAL_ID, ACTIVE FROM DEPENDENCY WHERE LOT_CODE='$lotCode' AND ACTIVE=                                      TRUE ORDER BY TERMINAL_ID DESC LIMIT 1";
                            $result = mysql_query($sql, $con);
                            $row    = mysql_fetch_array($result);
                            $total  = mysql_num_rows($result);
                            if ($total <= 0) {               // NO RECORDS FOUND GO TO TERMINAL 1   == optional
                               echo "notran";                
                            }     
                            else {
                               echo $row['TERMINAL_ID'] ; 
                            }   
                        }
                        
                        else {
                            $sql = "SELECT LOT_CODE, TERMINAL_ID, ACTIVE FROM DEPENDENCY WHERE LOT_CODE='$lotCode' AND                                              TERMINAL_ID='$terminalNo' AND ACTIVE=TRUE";
                            $result = mysql_query($sql, $con);
                            $total = mysql_num_rows($result);
                            if ($total <= 0 || $total >= 0) {
                                echo "G";    
                            }
                        }
                                                
                }
                else {
                        $sql = "SELECT LOT_CODE, TERMINAL_ID, ACTIVE FROM DEPENDENCY WHERE LOT_CODE='$lotCode' AND ACTIVE=                                      TRUE ORDER BY TERMINAL_ID DESC LIMIT 1";
                        $result = mysql_query($sql, $con);
                        $row    = mysql_fetch_array($result);
                        $total  = mysql_num_rows($result);
                        echo $row['TERMINAL_ID'] ; 
                }
            }
            
            else {
      
                $sql = "SELECT LOT_CODE, TERMINAL_ID, ACTIVE FROM DEPENDENCY WHERE LOT_CODE='$lotCode' AND                                          TERMINAL_ID='$terminalNo' AND ACTIVE=TRUE";
                $result = mysql_query($sql, $con);
                $total = mysql_num_rows($result);
                
                if ($total <= 0) {                    $preTerminal = ((integer)($terminalNo) - 1);
                   $preTerminal = (string)($preTerminal);
                   
  
                   $sql = "SELECT LOT_CODE, TERMINAL_ID, ACTIVE FROM DEPENDENCY WHERE LOT_CODE='$lotCode' AND                                          TERMINAL_ID='$preTerminal' AND ACTIVE=TRUE";
                   $result = mysql_query($sql, $con);    
                   $total = mysql_num_rows($result);
                   
                   if ($total <= 0) {                        
                       $sql = "SELECT LOT_CODE, TERMINAL_ID, ACTIVE FROM DEPENDENCY WHERE LOT_CODE='$lotCode' AND  ACTIVE=                                  TRUE ORDER BY TERMINAL_ID DESC LIMIT 1";
                       $result = mysql_query($sql, $con);
                       $row = mysql_fetch_array($result);
                       $total = mysql_num_rows($result);
                                         if ($total <= 0) {               // NO RECORDS FOUND GO TO TERMINAL 1   == optional
                           echo "notran";                
                       }                                            
                       else {                           
                           echo $row['TERMINAL_ID'];    // GET THE LAST TERMINAL NUMBER ACTIVE ADD 1 HERE TO DISPLAY WHICH                                                           TERMINAL TO GO
                       }                                
                   }   
                   else {
                       echo "G";
                   }
                }
                else {
                     
                                         $sql = "SELECT LOT_CODE, TERMINAL_ID, ACTIVE FROM DEPENDENCY WHERE LOT_CODE='$lotCode' AND                                              ACTIVE=TRUE ORDER BY TERMINAL_ID DESC LIMIT 1";
                    $result = mysql_query($sql, $con);
                    $row    = mysql_fetch_array($result);
                    $total  = mysql_num_rows($result);
       
                    echo $row['TERMINAL_ID'] ; ACTIVE                                                    ADD 1 HERE TO DISPLAY WHICH TERMINAL TO GO
                 
                }
            }        }  
    }

    if ($lotCodeDownGrade != "") {
        $sql = "SELECT BARCODE FROM LEGALCODES WHERE BARCODE='$lotCodeDownGrade'";
        $result = mysql_query($sql, $con);
        $total = mysql_num_rows($result);
        if ($total <= 0) {
            echo "X"; // X - for non existent in the mes table
        }
        else {
             
            $sql = "SELECT LOT_CODE, TERMINAL_ID, ACTIVE FROM DEPENDENCY WHERE LOT_CODE='$lotCodeDownGrade' AND 
                    ACTIVE=TRUE";
            
            $result = mysql_query($sql, $con);
            $total = mysql_num_rows($result);
            if ($total <= 0) {
                echo "0"; // continue to transact
            }
            else {
                       $sql    = "SELECT LOT_CODE, TERMINAL_ID, ACTIVE FROM DEPENDENCY WHERE LOT_CODE='$lotCodeDownGrade' AND 
                          ACTIVE=TRUE ORDER BY TERMINAL_ID DESC LIMIT 1";
                
                $result = mysql_query($sql, $con);
                
                $row    = mysql_fetch_array($result);
                $total  = mysql_num_rows($result);
          
                echo $row['TERMINAL_ID'] ;                                               
            }
        }
    }
}
  
else {
    if ($lotCode != "") {
        $sql = "SELECT BARCODE FROM LEGALCODES WHERE BARCODE='$lotCode'";
        $result = mysql_query($sql, $con);
        $total = mysql_num_rows($result);
        
        if ($total <= 0) {
            echo "X"; // X - for non existent in the mes table
        }
        
        else {
                   $sql = "SELECT LOT_CODE, TERMINAL_ID, ACTIVE FROM DEPENDENCY WHERE LOT_CODE='$lotCode' AND 
                    TERMINAL_ID='$terminalNo' AND ACTIVE=TRUE";
            $result = mysql_query($sql, $con);
            $total = mysql_num_rows($result);
            
            if ($total <= 0) {  // wala nakita - then tsek if nag exist sa terminal na sinundan
               $preTerminal = ((integer)($terminalNo) - 1);
               $preTerminal = (string)($preTerminal);
               
                            $sql = "SELECT LOT_CODE, TERMINAL_ID, ACTIVE FROM DEPENDENCY WHERE LOT_CODE='$lotCode' AND 
                      TERMINAL_ID='$preTerminal' AND ACTIVE=TRUE";
               
               $result = mysql_query($sql, $con);    
               $total = mysql_num_rows($result);
               if ($total <= 0) {                     $sql = "SELECT LOT_CODE, TERMINAL_ID, ACTIVE FROM DEPENDENCY WHERE LOT_CODE='$lotCode' 
                          AND ACTIVE=TRUE ORDER BY TERMINAL_ID DESC LIMIT 1";
                   $result = mysql_query($sql, $con);
                   $row = mysql_fetch_array($result);
                   $total = mysql_num_rows($result);

                   if ($total <= 0) {               // NO RECORDS FOUND GO TO TERMINAL 1   == optional
                       echo "notran";                
                   }                                            
                   else {                           
                       echo $row['TERMINAL_ID'];    // GET THE LAST TERMINAL NUMBER ACTIVE ADD 1 HERE TO DISPLAY WHICH TERMINAL TO GO
                   }                                
               }   
               else {
                   echo "G";
               }
            }
            else { 
               
                $sql    = "SELECT LOT_CODE, TERMINAL_ID, ACTIVE FROM DEPENDENCY WHERE LOT_CODE='$lotCode' AND ACTIVE=                                  TRUE ORDER BY TERMINAL_ID DESC LIMIT 1";
                $result = mysql_query($sql, $con);
                $row    = mysql_fetch_array($result);
                $total  = mysql_num_rows($result);

                echo $row['TERMINAL_ID'] ; 
            }
        }
    }
}   
mysql_close($con);   
?>
Code:
function unUsedLotId(txtElemID){

    var txtElemID_Active = txtElemID;

    responsePHP = "no_reply";
    changeFocus = false;
    var termNo = terminalNo(); 
    ajaxRequest = remoteRequestObject(); 
    ajaxRequest.onreadystatechange = function(){
        if (ajaxRequest.readyState==4 && ajaxRequest.status==200) {
             
  
               responsePHP = ajaxRequest.responseText; 
          

          
          prerequisites' : 'Tag unused';
            if (responsePHP == "failed") {
                txtElemID_Active.disabled = false;
                txtElemID_Active.value = "";
                txtElemID_Active.focus();
                notify("Report to MIS<br /> Please scan again.");
            }
      
            else if (responsePHP == "X") {
                              notify("Lot ID invalid. Scan Again.");
                if (txtElemID_Active.disabled) {
                    txtElemID_Active.disabled = false;                 
                }
                txtElemID_Active.value = "";
                txtElemID_Active.focus();  
            }
           
            else if (responsePHP =="0" || responsePHP =="G"){
               
               if (txtElemID_Name == "txtLotCode") {
                   window.LotID = (txtElemID_Active.value)
               }   
               if (txtElemID_Name == "txtLotCodeDownGrade") {
                   window.LotID_Down = (txtElemID_Active.value)
               }
               
               
               strip(txtElemID_Active) 
 
               if (termNo == "1") {
                   isSelected('txtLotCode', 'selWeight_MachineID'); 
               }
               if (termNo == "2" || termNo == "3") {
                   isSelected('txtLotCode', 'txtKitWeight'); 
               }
               if (termNo == "4" || termNo == "5" || termNo == "6" || termNo == "7") {
 
                   if (termNo == "4") {
                    
                        var chkDownGrade  = document.getElementById('chkDownGrade')
                        if (chkDownGrade.checked == 1) {
                    
                              if (txtElemID_Name == 'txtLotCode') {
                                 isSelected('txtLotCode', 'txtLotCodeDownGrade');
                              }
                              
                              if (txtElemID_Name == 'txtLotCodeDownGrade') {
                                 isSelected('txtLotCodeDownGrade', 'selMachineID');
                              }
                        }
                        else {
                     
                              if (txtElemID_Name == 'txtLotCode') {
                                 isSelected('txtLotCode', 'selMachineID');
                              }
                        
                        }                         
                   }
                   else {
                       
                       isSelected('txtLotCode', 'selMachineID'); 
                   }

               
               
               }
               if (document.getElementById('notice')!== null) {
                   document.getElementsByTagName('body')[0].removeChild(document.getElementById('notice')) //>> clear the box 
               } 
            }
           
            else if (responsePHP == "notran") {
               var mensahe1 = "Please return to<br /><span style='font-size:30px;'>Chemical Weighing<br /> or Supervisor</span>";
               notify(mensahe1);  
               
               if (txtElemID_Active.disabled) {
                   txtElemID_Active.disabled = false;                 
               }
               txtElemID_Active.value = "";
               txtElemID_Active.focus();
            }
            
            else {
          
               var mensahe1 = "Last Process: <span style='font-size:30px;'> Terminal " + responsePHP + "</span><br /><br />";
               var mensahe2 = "Pls. Proceed: <span style='font-size:30px;'> Terminal " + (parseInt(responsePHP) + 1) + "</span>"; 
               
               notify(mensahe1 + mensahe2);
           
               if (txtElemID_Active.disabled) {
                   txtElemID_Active.disabled = false;                 
               }
               txtElemID_Active.value = "";
               txtElemID_Active.focus();
            }
       
        }
    }   

var txtElemID_Name = txtElemID_Active.id;      

if (termNo == "4") {
    var downGrade  = document.getElementById('chkDownGrade').checked;
    var str =  txtElemID_Active.value +  "&n=" + termNo +  "&down=" + downGrade;
}
else {
    var str =  txtElemID_Active.value +  "&n=" + termNo;
}

if (txtElemID_Name == "txtLotCode") {
      var url = "verifyLotId.php?normal=" + str; 
}   
if (txtElemID_Name == "txtLotCodeDownGrade") {
       var url = "verifyLotId.php?downgrade=" + str; 
}


ajaxRequest.open("GET", url, true);

ajaxRequest.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");

ajaxRequest.send(null);


ajaxTimeOut = window.setTimeout("timeOut('" + txtElemID_Name + "');", 6000);
        
}