为什么我的prepare语句未执行?

问题描述 投票:-1回答:1

我验证语句和连接,并且两者均有效。我不明白为什么我的第二个和第三个工作完美时为什么我的第一个prepare语句没有被执行!

这是我的代码:

require('connection.php');

$id = $_SESSION['ID'];
$score = $_COOKIE['score'];
$applesEaten = $score - 1;

if ($stmt = $conn->prepare('UPDATE Player SET score = score + ?, dailyScore = dailyScore + ?, monthScore = monthScore + ?, applesEaten = applesEaten + ?, gamesPlayed = gamesPlayed + 1 WHERE ID = ?')){
    $stmt->bind_param('iiiii',$score,$score,$score,$id,$applesEaten);
    $stmt->execute();

    $stmt->close();
}

if ($stmt = $conn->prepare('SELECT bestScore FROM Player WHERE ID = ?')) {
    $stmt->bind_param('i',$id);
    $stmt->execute();
    $result = $stmt->get_result();

    $data = $result->fetch_assoc();

    $bestScore = $data['bestScore'];

    $stmt->free_result();
    $stmt->close();
}

if ($score > $bestScore){
    if ($stmt = $conn->prepare('UPDATE Player SET bestScore = ? WHERE ID = ?')) {
        $stmt->bind_param('ii',$score,$id);
        $stmt->execute();

        $stmt->close();

    }
}</code>

谢谢

php html mysql sql
1个回答
0
投票

这是我的桌子:

CREATE TABLE Player ( ID int(11) NOT NULL, mail varchar(30) COLLATE utf8_unicode_ci NOT NULL, password varchar(30) COLLATE utf8_unicode_ci NOT NULL, score int(11) NOT NULL DEFAULT '0', dailyScore int(11) NOT NULL DEFAULT '0', monthScore int(11) NOT NULL DEFAULT '0', country varchar(20) COLLATE utf8_unicode_ci NOT NULL, gamesPlayed int(11) NOT NULL DEFAULT '0', signInDate timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, bestScore int(11) NOT NULL DEFAULT '1', applesEaten int(11) NOT NULL DEFAULT '0' ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

我没有任何错误日志

© www.soinside.com 2019 - 2024. All rights reserved.