加料 没问题。退料就会出现错误提示。请假是哪里错了啊?各位帮忙了。谢谢。
<?php
require_once("../common/matFunction.php");  //引入入库函数表
require_once("../common/con_db.php");function forup2($number,$id,$fo){
      con_db();  
      $ques="select sellNum + ".$number." as nowrest from getMatInfo  where id=".$id; 
       $rels =mysql_query($ques);   
       while($rows=mysql_fetch_array($rels)){ 
      $resN=trim($rows[nowrest]);  
    }
  if ($resN<0){
    exit("退还数量不能大于发出数。"); 
  }
  else{
   forupdate($id,"sellNum",$resN,"getMatInfo");
    if($fo=="y"){
    forup2($numbers,$id,"n");
    }
  } 
}function forup($numbers,$ids,$fo){ 
    con_db();   
          $ques="select id as mid,matRest - ".$numbers." as nowrest from matStorage where id in (select toStoid from getMatInfo where id =" . $ids.")";        con_db();   
       $rels =mysql_query($ques);   
       while($row=mysql_fetch_array($rels)){ 
      $resN=trim($row[nowrest]);
      $mid=trim($row[mid]); 
    }
  if ($resN<0){
    exit("发出数量不能大于库存剩余数。"); 
  }
  else{
    forupdate($mid,"matRest",$resN,"matStorage");
     if($fo=="y"){
       forup2($numbers,$ids,"n");
      }
  }  
}  $upid=trim($_GET["id"]);
  $sel=trim($_GET["sel"]);
  $upsid=trim($_POST["upid"]);
  $dowhat=trim($_POST["opt"]);
  $num=trim($_POST["nums"]);
if($sel=="sel"){   
  if ($num=="" || !is_numeric($num) || $num <=0){
  exit("数量错误");
  }
  
  if ($dowhat=="" ){
  exit("请选择是加料还是退料");
  }
  
   if($dowhat=="add"){
    forup($num,$upsid,"y");
   }  
   
   if($dowhat=="rdu"){ 
    $num = $num * (-1); 
    forup2($num,$upsid,"y");
   }
  }  
?>
<form name="form1" method="post" action="addRdu.php?sel=sel">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>加料 
      <input type="radio" name="opt" value="add">
    </td>
    </tr>
  <tr>
    <td>退料 
      <input type="radio" name="opt" value="rdu">
    </td>
    </tr>
  <tr>
    <td>数量 
          <input name="nums" type="text" size="10" maxlength="4">
          <input name="upid" type="hidden" value="<?php echo $upid;?>">         
          <input type="submit" name="Submit" value="提交">
            </td>
    </tr>
</table>
</form> 

解决方案 »

  1.   

    forupdate 函数   function forupdate($id,$ziduan,$newvals,$table){
          con_db();  
              $strsql="update ".$table." set ".$ziduan."='".$newvals."' where id='".$id."'"; 
          $rel =mysql_query($strsql); 
      if($rel){ 
        echo "已经成功修改<br>";
      }
      else{
         echo "修改失败<br>";
      } 
       }