简体   繁体   English

PHP练习Cookie

[英]PHP exercise with cookies

i need to get score +10 when i answer the question right but it is not working here is my code: 当我回答正确的问题时,我需要得到+10的分数,但是它在这里不起作用,这是我的代码:

Hi thanks for the answers, i am now trying this but the score isnt going up by 10 if i answer the question good: 嗨,谢谢你的回答,我现在正在尝试,但是如果我回答的是好问题,分数不会增加10:

    <?php
    // de functie rand() bepaalt een random getal tussen het eerste en       tweede opgegeven getal
$getal1 = rand (1, 10);
$getal2 = rand (1, 20);
$score = 0;

if(isset($_POST['verzend'])){
    $antwoord = $_POST['uitkomst'];
    $somantwoord = $getal1 * $getal2;

    if($antwoord == $somantwoord)
    {
        $score + 10;
    }
}

echo $score;

HTML 的HTML

<form method='post' action='index.php'>
 <input name='getal1' type='text' disabled value='$getal1'>&nbsp;*&nbsp;
 <input name='getal2' type='text' disabled value='$getal2'> =
 <input name='uitkomst' type='text' value='' id='uitkomst'>
 <input type='submit' value='verzend' name='verzend'>
 </form>

Try this code: 试试这个代码:

<?php
// de functie rand() bepaalt een random getal tussen het eerste en       tweede opgegeven getal
$getal1 = rand(1, 10);
$getal2 = rand(1, 20);
$score = 0;

if(isset($_POST['verzend'])) {
    $antwoord = (int)$_POST['uitkomst'];
    $somantwoord = $getal1 * $getal2;

    if($antwoord === $somantwoord) {
        $score += 10;
    }
}

echo $score;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM