Page 1 of 1

How to update a table based on the checkbox value

Posted: Tue Mar 03, 2009 6:43 am
by ullasvk
Hello friends.
I am newbie to PHP. I have been working hard lately for this solution but all in vain. Can any body help me please.
I have two tables order table and inventory table bot have same values except that order table has some additional values.I have written code for comparing, but the actual problem is i want to update a field called bundle_no[bun_no] in order table with the bundle no in inventory table, if both have same values.Can any body help me please. I have almost written the code but i dose'nt work properly.
Here is the code

Code: Select all

 
 
<?php
include("includes/connection.php");
if(isset($_REQUEST['submit'])&& isset($_REQUEST['bun_id']))
{
 if(is_array($_REQUEST['bun_id']) )
  {
    $a=$_REQUEST['bun_id'];
    
    for($i=0;$i<count($a);$i++)
    {
        if(($_REQUEST['inv'])||(is_array($_REQUEST['inv'])))
        {
            $b=$_REQUEST['inv'];
            for($j=0;$j<count($b);$j++)
            {
                if ($a[$i] == $b[$j])
                {
                
                    $result= mysql_query("SELECT * FROM ORDER_DETAIL WHERE SL_N0 ='$a[$i]'");
                    $line  =  mysql_fetch_array($result);
                    $result1 =mysql_query("SELECT * FROM INVENTORY WHERE DENSITY = '".$line["DENSITY"]."',SI_ID = '".$line["SI_ID"]."',THICK = '".$line["THICK"]."',NO_OF_SHEETS = '".$line["NO_OF_SHEETS"]."',GRADE = '".$line["GRADE"]."',COLOR = '".$line["COLOR"]."' LIMIT 0,1");
                    $line1 =  mysql_fetch_array($result1);
                    $result2= mysql_query("UPDATE ORDER_DETAIL SET TOT_THICK = '".$_REQUEST["tot_thick"][$j]."',WEIGHT = '".$_REQUEST["weight"][$j]."', BUN_NO = '".$line1["BUN_NO"]."',INV_SL = '".$line1["SL_NO"]."'WHERE SL_NO = '$a[$i]' AND BUN_NO ='0'");
                    $result3= mysql_query("UPDATE INVENTORY SET OR_ID = '".$line["OR_ID"]."' WHERE SL_NO = '".$line["INV_SL"]."' ");
                }
            else
        {   
                    $result1= mysql_query("SELECT MAX(bun_no) from order_detail");
                    $a1[0]  =  mysql_fetch_array($result1);
                    $result2= mysql_query("SELECT MAX(bun_no) from inventory");
                    $b[0]  =  mysql_fetch_array($result2);
                    $c=($a1[0]>$b[0]?$a[0]:$b[0]);
                    $c1=$c[0]+1;
                    $result2= mysql_query("UPDATE ORDER_DETAIL SET TOT_THICK = '".$_REQUEST["tot_thick"][$j]."',WEIGHT = '".$_REQUEST["weight"][$j]."', BUN_NO = '$c1'WHERE SL_NO ='$a[$i]' AND BUN_NO ='0' "); 
        }   
                
            }
        }
        
    }
  }
  else
  {
        
                    $result1= mysql_query("SELECT MAX(bun_no) from order_detail");
                    $a1[0]  =  mysql_fetch_array($result1);
                    $result2= mysql_query("SELECT MAX(bun_no) from inventory");
                    $b[0]  =  mysql_fetch_array($result2);
                    $c=($a1[0]>$b[0]?$a[0]:$b[0]);
                    $c1=$c[0]+1;
                    $result2= mysql_query("UPDATE ORDER_DETAIL SET TOT_THICK = '".$_REQUEST["tot_thick"]."',WEIGHT = '".$_REQUEST["weight"]."', BUN_NO = '$c1'WHERE SL_NO ='$a[$i]' AND BUN_NO ='0' "); 
    
  }
 
}
?>  
    
 
Thanks in Advance.

Re: How to update a table based on the checkbox value

Posted: Tue Mar 03, 2009 7:00 am
by susrisha
can you post us any error messages that you are getting from the stated code??

Rule 1 of development :
Always expect it to fail and give out an error. ;)