0

我有一个函数,它首先检查是否存在一行,如果不存在则插入数据。如果有任何失败,它应该返回 false。当我运行该函数并使用 var_dump 检查返回时,它返回 true。我假设数据已插入数据库,但事实并非如此。为什么会这样做?我的功能有问题吗?

function add_tier ($mysqli, $project_id, $tier_number, $wanted, $in_return, $limit) {

    if ($result = $mysqli->query("SELECT COUNT(tier_id) FROM `tier` WHERE `project_id` 
    = $project_id AND `tier_number` = $tier_number")){

      if ($return < 1) {

        if ($stmt = $mysqli->prepare("INSERT INTO `tier` (`project_id`, 
        `tier_number`, `wanted`, `in_return`, `limit`) VALUES (?, ?, ?, ?, ?)")){

        $stmt->bind_param('iissi', $project_id, $tier_number, $wanted, $in_return, 
        $limit);

        $return = $stmt->execute();

        $stmt->close();

        return $return;

        } else {return false;}      

      } else {return false;}            

    }  else {return false;}

}
4

1 回答 1

1

(从评论继续)您似乎没有$return在此行中的任何地方定义:

if ($return < 1) {
于 2012-10-02T02:09:21.577 回答