PHP事务将无法完成

时间:2016-12-14 16:35:41

标签: php mysql transactions

我的PHP事务不会执行。我可以访问它,因为“插入”工作正常。但是当我插入“付费”时,我想删除“tickets_given”中的玩家数据 - 但这不起作用。

你能在我的代码中看到一些错误吗?

if(isset($_POST['register'])){
    $playerId = $_POST['playerId'];
    $amount = $_POST['amount'];
    $ticket->registerPayment($playerId, $amount);
}

<form action='?registerPayment=<?php echo $playerId; ?>' method="post">
            <input type="hidden" name="playerId" value="<?php echo $playerId; ?>">
            <input type="hidden" name="register" value="true">
            <input type="text" name="amount" id="amount" required="required" placeholder="Beløb"/>
            <input type="submit" value="Registrér betaling" name="payment_submit"/><br />
</form>

function registerPayment($playerId, $amount) {
        $this->conn->beginTransaction();
        $query = $this->conn->prepare("INSERT INTO paid (ref_player, amount) VALUES ('$playerId', '$amount')");          
        $query->execute();
        $query = $this->conn->prepare("DELETE FROM tickets_given WHERE ref_player = '$playerId'");
        $this->conn->commit();
        return $query;
    }

0 个答案:

没有答案