If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > PHP > Sum of numbers that was insert will automatic compute and appear in total text field

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-22-10, 20:49
newphpcoder newphpcoder is offline
Registered User
 
Join Date: Dec 2010
Posts: 126
Sum of numbers that was insert will automatic compute and appear in total text field

Good day!

I have a problem in adding codes in my php codes, but I have the concept of codes that I want to add in my php codes, but I don't know if it is right. Kindly check my codes thank you.


And here is the code I want to add:
Code:
<?php

$rexist = 0;
if($_POST["clt_no"])
{
   $opname = $_POST["opname"];
   $inqty = $_POST["inqty"];
   $outqty = $_POST["outqty"];
   
   $totalarr = count($opname) - 1;
    for($ctr=0; $ctr < $totalarr; $ctr++)
        {
        $inqty[$ctr] = (float) $inqty[$ctr];
        $outqtyqty[$ctr] = (float) $outqty[$ctr];
        
         $query = "INSERT INTO clt_traceability (operation_name, input_qty, clt_transact_id) VALUES ('" . $opname[$ctr] . "',  '" . $inqty[$ctr] . "', '" . $outqty[$ctr] . "', '" . $clt_transact_id . "')";
        $result = mysql_query($query);
        }   
        
    $query = "SELECT * FROM clt_transact WHERE  clt_no = '" . $_POST["clt_no"] . "'";
    $result_no = mysql_query($query);
        if($result_no)
            {
            if(mysql_num_rows($result_no) > 0 )
            {
            $operation1_input = 0;
            $operation1_inputtotal = 0;
            
            $query = "SELECT SUM(t.input_qty) AS operation1_input FROM clt_traceability t, p WHERE t.clt_transact_id = p.clt_transact_id AND t.operation_name 'Operation1' AND p.clt_no='" . $_POST["clt_no"] . "'";
            $resultyield = mysql_query($query);
            if($resultyield)
                {
                    if(mysql_num_rows($resultyield) > 0)$operation1_input =mysql_result($resultyield,0,"operation1_input");
                }
          
            $query = "SELECT operation_name FROM clt_traceability t, clt_transact c WHERE t.operation_name = 'Operation1_total' AND t.clt_transact_id = c.clt_transact_id";
            $result = mysql_query($query);
            if($result > 0)
            {           
            $operation1_inputtotal = $operation1_input;
          
            }
            }
            
            if(mysql_num_rows($result_no) > 0 )
            {
            $operation1_output = 0;
            $operation1_outputtotal = 0;
            
            $query = "SELECT SUM(t.output_qty) AS operation1_output FROM clt_traceability t, p WHERE t.clt_transact_id = p.clt_transact_id AND t.operation_name 'Operation1' AND p.clt_no='" . $_POST["clt_no"] . "'";
            $resultyield = mysql_query($query);
            if($resultyield)
                {
                    if(mysql_num_rows($resultyield) > 0)$operation1_output =mysql_result($resultyield,0,"operation1_output");
                }
          
            $query = "SELECT operation_name FROM clt_traceability t, clt_transact c WHERE t.operation_name = 'Operation1_total' AND t.clt_transact_id = c.clt_transact_id";
            $result = mysql_query($query);
            if($result > 0)
            {           
            $operation1_outputtotal = $operation1_output;
          
            }
            }
            
            if(mysql_num_rows($result_no) > 0 )
            {
            $operation2_input = 0;
            $operation2_inputtotal = 0;
            
            $query = "SELECT SUM(t.input_qty) AS operation2_input FROM clt_traceability t, p WHERE t.clt_transact_id = p.clt_transact_id AND t.operation_name 'Operation2' AND p.clt_no='" . $_POST["clt_no"] . "'";
            $resultyield = mysql_query($query);
            if($resultyield)
                {
                    if(mysql_num_rows($resultyield) > 0)$operation2_input =mysql_result($resultyield,0,"operation2_input");
                }
        
            $query = "SELECT operation_name FROM clt_traceability t, clt_transact c WHERE t.operation_name = 'Operation2 _total' AND t.clt_transact_id = c.clt_transact_id";
            $result = mysql_query($query);
            if($result > 0)
            {           
            $operation2_total = $operation2_input;
          
            }
            }
            
             if(mysql_num_rows($result_no) > 0 )
            {
            $operation2_output = 0;
            $operation2_ouputtotal = 0;
            
            $query = "SELECT SUM(t.output_qty) AS operation2_output FROM clt_traceability t, p WHERE t.clt_transact_id = p.clt_transact_id AND t.operation_name 'Operation2' AND p.clt_no='" . $_POST["clt_no"] . "'";
            $resultyield = mysql_query($query);
            if($resultyield)
                {
                    if(mysql_num_rows($resultyield) > 0)$operation2_output =mysql_result($resultyield,0,"operation2_output");
                }
        
            $query = "SELECT operation_name FROM clt_traceability t, clt_transact c WHERE t.operation_name = 'Operation2 _total' AND t.clt_transact_id = c.clt_transact_id";
            $result = mysql_query($query);
            if($result > 0)
            {           
            $operation2_outputtotal = $operation2_output;
          
            }
            }
    }
}
$rexist = 0;
?>

<html>
<head>
    <style type="text/css">
    .myclass {
     font-size: 10pt; font-family:Arial, Helvetica, sans-serif;
    }
    </style>
    
    <script type="text/javascript">
document.onkeypress = function(e){
    e = e || event; e.returnValue = true;
    var t = e.target || e.srcElement, re = /^(inqty|outqty)(\d+)$/, f = arguments.callee, m, i;
    function next(){
        if(!f.els && (m = t.form) === document.forms.clttype){
            var ipts = m.getElementsByTagName('input'), els = []; i = ipts.length - 1;
            for (i; i > -1; --i){
                if(ipts[i].type && ipts[i].type.toLowerCase() === 'text'){
                    els.push(ipts[i]);
                }
            }
            f.els = els;
        }
        if(f.els){
            i = f.els.length - 1;
            for (i; i > -1; --i){
                if(f.els[i] === t && (m = f.els[i - 1])){
                    m.focus();
                }
            }
        }
    }
    if((m = re.exec(t.id)) && e.keyCode === 13){
        e.returnValue = false;
        t.form.elements['varqty' + m[2]].value = t.form.elements['inqty' + m[2]].value - t.form.elements['outqty' + m[2]].value;
    } else if (t.type && e.keyCode === 13 && t.type.toLowerCase() !== 'submit') {
        e.returnValue = false;
    }
    if(!e.returnValue){
        next();
        if(e.preventDefault){e.preventDefault();}
    }
    return e.returnValue;
}
</script>
</head>
<body>
<form action='frame.php' method="post" name="clttype">

<?php
    $rexist = 1;
    
    
    
    $query = "SELECT * FROM clt_trace_operations ORDER BY operation_name";
    $last_operation_name = "";
    $result = mysql_query($query);
    if($result)
        {
        $rexist = 1;
        echo "<table>";
        echo "<tr><th class='myclass'>OPERATIONS</th><th class='myclass'>INPUT <br/> QTY</th><th class='myclass'>OUTPUT <br/> QTY</th><th class='myclass'>VARIANCE Qty</th></tr>";
        $totalrows = mysql_num_rows($result);
        $trows = $totalrows - 1;
        for($ctr = 0; $ctr < $trows; $ctr++)
            {
            $row = mysql_fetch_array($result);
            $tctr = $ctr + 1;
            echo "\n\t<tr>";
            echo "\n\t\t<td>";
            if ($last_operation_name != $row["operation_name"]) echo $row["operation_name"];
            $last_operation_name = $row["operation_name"];
            echo "<input type='hidden' width='400' name='opname[]' value='" . $row["operation_name"] . "' /></td>";  
            echo "\n\t\t<td><input size='6' type='text' name='inqty[]' id='inqty" . $ctr . "' /></td>";
            echo "\n\t\t<td><input size='6' type='text' name='outqty[]' id='outqty" . $ctr . "' ></td>";
            echo "\n\t\t<td><input size='6' type='text' name='varqty[]' id='varqty" . $ctr . "' /></td>";
            echo "\n\t</tr>";
            }
        if($totalrows > 1);
            {
            $row = mysql_fetch_array($result);
            echo "\n\t<tr>";
            echo "\n\t\t<td>";
            if ($last_operation_name != $row["operation_name"]) echo $row["operation_name"];
            $last_operation_name = $row["operation_name"];
            echo "<input type='hidden' width='400' name='opname[]' value='" . $row["operation_name"] . "' /></td>";   
            echo "<input type='hidden' name='opname[]' value='" . $row["operation_name"] . "' /></td>";
            echo "\n\t\t<td><input size='6' type='text' name='inqty[]' id='inqty"  . $ctr . "' /></td>";
            echo "\n\t\t<td><input size='6' type='text' name='outqty[]'  id='outqty" . $ctr . "'  /></td>";
            echo "\n\t\t<td><input size='6' type='text' name='varqty[]' value=''  id='varqty" . $ctr . "' /></td>";
            echo "\n\t</tr>";
            }
        echo "</table>";
        }   
           echo "<p><input type='submit' value='  Save  ' id='saveform' /></p>";
    echo "<input type='hidden' name='clt_typeno' value='" . $_POST["clt_typeno"] . "' />";
?>
</form>
</body>
</html>

I want to happen be in operation1 and operation 2 the input qty and output qty will automatically compute the sum and the result will appear in the total.
I don't know how thus the result should be appearing automatically in the total textfield. I mean is the sum of input qty of operation 1 will automatic appear in operation1_total and also with the output qty, same with the operation2.

I got this error:
Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in D:\xampp\htdocs\sumtot.php on line 164

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in D:\xampp\htdocs\sumtot.php on line 164
Kindly tell me what is missing or wrong.

Thank you
Reply With Quote
  #2 (permalink)  
Old 12-23-10, 02:38
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,262
the error message is explicitly telling you that user ODBC is not allowed to connect to the database server on line 164 of script sumtot

so you need to open up that script, navigate to that line number and examine the code there

error messages in php can be confusing they report when an error was recognised, not neccesarily where an error lies, but in this case its deffo on line 164.

consider using the 'or die' construct to trap errors.
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #3 (permalink)  
Old 12-23-10, 03:23
newphpcoder newphpcoder is offline
Registered User
 
Join Date: Dec 2010
Posts: 126
I resolved that error by adding the connection code to database. but my code did not work. It did not sum the input qty


Thank you
Reply With Quote
  #4 (permalink)  
Old 12-23-10, 03:27
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,262
?
so what steps have you taken to identify why 'your code did not work'
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #5 (permalink)  
Old 12-27-10, 20:09
newphpcoder newphpcoder is offline
Registered User
 
Join Date: Dec 2010
Posts: 126
I tried to trace code if what code did not read.

Here is code did not read:

PHP Code:
{
   
$opname $_POST["opname"];
   
$inqty $_POST["inqty"];
   
$outqty $_POST["outqty"];
   
   
$totalarr count($opname) - 1;
    for(
$ctr=0$ctr $totalarr$ctr++)
        {
        
$inqty[$ctr] = (float) $inqty[$ctr];
        
$outqtyqty[$ctr] = (float) $outqty[$ctr];
        
         
$query "INSERT INTO clt_traceability (operation_name, input_qty, clt_transact_id) VALUES ('" $opname[$ctr] . "',  '" $inqty[$ctr] . "', '" $outqty[$ctr] . "', '" $clt_transact_id "')";
        
$result mysql_query($query);
        }   
        
    
$query "SELECT * FROM clt_transact WHERE  clt_no = '" $_POST["clt_no"] . "'";
    
$result_no mysql_query($query);
        if(
$result_no)
            {
            if(
mysql_num_rows($result_no) > )
            {
            
$operation1_input 0;
            
$operation1_inputtotal 0;
            
            
$query "SELECT SUM(t.input_qty) AS operation1_input FROM clt_traceability t, p WHERE t.clt_transact_id = p.clt_transact_id AND t.operation_name 'Operation1' AND p.clt_no='" $_POST["clt_no"] . "'";
            
$resultyield mysql_query($query);
            if(
$resultyield)
                {
                    if(
mysql_num_rows($resultyield) > 0)$operation1_input =mysql_result($resultyield,0,"operation1_input");
                }
          
            
$query "SELECT operation_name FROM clt_traceability t, clt_transact c WHERE t.operation_name = 'Operation1_total' AND t.clt_transact_id = c.clt_transact_id";
            
$result mysql_query($query);
            if(
$result 0)
            {           
            
$operation1_inputtotal $operation1_input;
          
            }
            }
            
            if(
mysql_num_rows($result_no) > )
            {
            
$operation1_output 0;
            
$operation1_outputtotal 0;
            
            
$query "SELECT SUM(t.output_qty) AS operation1_output FROM clt_traceability t, p WHERE t.clt_transact_id = p.clt_transact_id AND t.operation_name 'Operation1' AND p.clt_no='" $_POST["clt_no"] . "'";
            
$resultyield mysql_query($query);
            if(
$resultyield)
                {
                    if(
mysql_num_rows($resultyield) > 0)$operation1_output =mysql_result($resultyield,0,"operation1_output");
                }
          
            
$query "SELECT operation_name FROM clt_traceability t, clt_transact c WHERE t.operation_name = 'Operation1_total' AND t.clt_transact_id = c.clt_transact_id";
            
$result mysql_query($query);
            if(
$result 0)
            {           
            
$operation1_outputtotal $operation1_output;
          
            }
            }
            
            if(
mysql_num_rows($result_no) > )
            {
            
$operation2_input 0;
            
$operation2_inputtotal 0;
            
            
$query "SELECT SUM(t.input_qty) AS operation2_input FROM clt_traceability t, p WHERE t.clt_transact_id = p.clt_transact_id AND t.operation_name 'Operation2' AND p.clt_no='" $_POST["clt_no"] . "'";
            
$resultyield mysql_query($query);
            if(
$resultyield)
                {
                    if(
mysql_num_rows($resultyield) > 0)$operation2_input =mysql_result($resultyield,0,"operation2_input");
                }
        
            
$query "SELECT operation_name FROM clt_traceability t, clt_transact c WHERE t.operation_name = 'Operation2 _total' AND t.clt_transact_id = c.clt_transact_id";
            
$result mysql_query($query);
            if(
$result 0)
            {           
            
$operation2_total $operation2_input;
          
            }
            }
            
             if(
mysql_num_rows($result_no) > )
            {
            
$operation2_output 0;
            
$operation2_ouputtotal 0;
            
            
$query "SELECT SUM(t.output_qty) AS operation2_output FROM clt_traceability t, p WHERE t.clt_transact_id = p.clt_transact_id AND t.operation_name 'Operation2' AND p.clt_no='" $_POST["clt_no"] . "'";
            
$resultyield mysql_query($query);
            if(
$resultyield)
                {
                    if(
mysql_num_rows($resultyield) > 0)$operation2_output =mysql_result($resultyield,0,"operation2_output");
                }
        
            
$query "SELECT operation_name FROM clt_traceability t, clt_transact c WHERE t.operation_name = 'Operation2 _total' AND t.clt_transact_id = c.clt_transact_id";
            
$result mysql_query($query);
            if(
$result 0)
            {           
            
$operation2_outputtotal $operation2_output;
          
            }
            }
    }

Reply With Quote
  #6 (permalink)  
Old 12-28-10, 06:57
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,262
so what is the problem you are looking for help with
frankly I don't have time, or inclination, to wade through your code to try to fidn a fault which is described as
Quote:
I tried to trace code if what code did not read.

Here is code did not read:
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On