分数板分配

时间:2015-10-24 19:02:45

标签: php forms session post

每次按下Verhogen,我都需要一个能够计算分数的应用程序。我尝试了会话,但显然这两个会话相互冲突。有没有办法来解决这个问题?

<?php
session_start();

if (!isset($_POST['thuisverhogen'])) {
    $_SESSION['thuisverhogen'] = 0;
} elseif (isset($_POST['thuisverhogen'])) {
    if (!($_SESSION['thuisverhogen'])) {
        $_SESSION['thuisverhogen'] = 1;
    } else {
        $thuisverhogen = $_SESSION['thuisverhogen'] + 1;
        $_SESSION['thuisverhogen'] = $thuisverhogen;
    }
}

if (!isset($_POST['uitverhogen'])) {
    $_SESSION['uitverhogen'] = 0;
} elseif (isset($_POST['uitverhogen'])) {
    if (!($_SESSION['uitverhogen'])) {
        $_SESSION['uitverhogen'] = 1;
    } else {
        $thuisverhogen = $_SESSION['uitverhogen'] + 1;
        $_SESSION['uitverhogen'] = $thuisverhogen;
    }
}
?>

<h2>SCORE</h2>
<form method="POST" action="2.php">
    Thuisscore: <input type="text" name="thuisscore" value="<?php echo $_SESSION['thuisverhogen'] ?>">
    <input type="submit" name="thuisverhogen" value="Verhogen"><br>

    Uitscore: <input type="text" name="uitscore" value="<?php echo $_SESSION['uitverhogen'] ?>">
    <input type="submit" name="uitverhogen" value="Verhogen">
</form>

1 个答案:

答案 0 :(得分:0)

找到了answare

if (isset($_POST['thuisscore'])) {

    $thuisscore = $_POST['thuisscore'];
} else {
    $thuisscore = 0;
}

if (isset($_POST['uitscore'])) {
    $uitscore = $_POST['uitscore'];
} else {
    $uitscore = 0;
}

//verhogen
if (isset($_POST['thuisverhogen'])) {
    $thuisscore = $thuisscore + 1;
} else {
    if (isset($_POST['verhooguit'])) {
        $uitscore = $uitscore + 1;
    }
}
?>

<h2>SCORE</h2>
<form method="POST" action="2.php">
    Thuisscore: <input type="text" name="thuisscore" value="<?php echo $thuisscore ?>">
    <input type="submit" name="thuisverhogen" value="Verhogen"><br>

    Uitscore: <input type="text" name="uitscore" value="<?php echo $uitscore ?>">
    <input type="submit" name="verhooguit" value="Verhogen"><br>

</form>