function getPP($Proname1)
{
$result = null;
$sql= "SELECT SUM(num) AS num FROM pro1 WHERE proname =?";
$sth = $this->dbh->prepare($sql);
$sth->bindValue(1,$Proname1,PDO::PARAM_STR);
//查询数据库
//执行预处理语句,并将结果保存在$sth中
$sth->setFetchMode(PDO::FETCH_ASSOC);
$sth->execute();
$result = $sth->fetch(PDO::FETCH_ASSOC);//只返回关联索引
   // 显式的关闭PDO连接
    $this->dbh = NULL;
   // [03]返回结果
    return $result; 
}function insPP1($ID,$PRO,$PRI,$NUM,$TOT,$DES)
{
$result = false;
$a=$this->getPP($PRO);
$PTO=($a['num']-$NUM);
$sql = "INSERT INTO pro(id,proname,price,num,total,description,inv) VALUES (?,?,?,?,?,?,?)";
try{
$sth = $this->dbh->prepare($sql);
// 准备预处理语句
   $sth->bindValue(1, $ID, PDO::PARAM_INT);
   $sth->bindValue(2, $PRO, PDO::PARAM_STR);
   $sth->bindValue(3, $PRI, PDO::PARAM_STR);
   $sth->bindValue(4, $NUM, PDO::PARAM_INT); 
   $sth->bindValue(5, $TOT, PDO::PARAM_STR);
   $sth->bindValue(6, $DES, PDO::PARAM_STR);
   $sth->bindValue(7, $PTO, PDO::PARAM_INT);
   $result = $sth->execute(); 
   // 执行插入操作并将是否成功的结果保存在一个变量中
   $this->dbh = NULL;
   $result = true;
   } catch (PDOException $err) {
   echo("出错,请重试或者联系管理员");
   die();
   }
   $result = $sth->execute(); 
   return $result;     
}

解决方案 »

  1.   

    $sql = "INSERT INTO pro(id,proname,price,num,total,description,inv) VALUES (?,?,?,?,?,?,?)";
    try{
    $sth = $this->dbh->prepare($sql);
    // 准备预处理语句
       $sth->bindValue(1, $ID, PDO::PARAM_INT);
       $sth->bindValue(2, $PRO, PDO::PARAM_STR);
       $sth->bindValue(3, $PRI, PDO::PARAM_STR);
       $sth->bindValue(4, $NUM, PDO::PARAM_INT); 
       $sth->bindValue(5, $TOT, PDO::PARAM_STR);
       $sth->bindValue(6, $DES, PDO::PARAM_STR);
       $sth->bindValue(7, $PTO, PDO::PARAM_INT);
       $result = $sth->execute(); 
       // 执行插入操作并将是否成功的结果保存在一个变量中
       $this->dbh = NULL;
       $result = true;
       } catch (PDOException $err) {
       echo("出错,请重试或者联系管理员");
       die();
       }
       $result = $sth->execute(); //这个有点多余
       return $result;     
    }
      

  2.   

    没有报错信息,问题就出在 $result = false;
    $a=$this->getPP($PRO);
    $PTO=($a['num']-$NUM);$sth->bindValue(7, $PTO, PDO::PARAM_INT);这三句
      

  3.   

    $sth->bindValue,$th->bindParam格式哪个可以,一个是常量,一个是变量