0

我正在尝试为诸如拼字游戏之类的物理游戏制作一个简单的记分员应用程序。我有两页,一页询问用户的姓名,另一页用于计算他们的分数。我想在第二页的分数旁边显示用户的姓名;例如,Max: 47。问题是页面只显示用户名一次。有人输入分数后,他们就会消失。我试过使用 cookie,但它们似乎只会因为不显示任何东西而使事情变得更糟!您可以在 ripdvd.x10.mx 访问应用程序,但不显示名称。有谁知道一个简单的解决方案?

第一页:

<html>

<head>
<title>Select Players</title>
<link rel=StyleSheet href="style.css" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>

<body>
    <form method="post" action="scoregen.php">
    <p class="par">
        <label for="player1">Please type in the one of the players first name:</label>
            <input type="text" id="player1" name="player1" size="17"  maxlength="17" value="Enter Name" class="textbox" />
    </p>

    <p class="par">
        <label for="player2">Please type in another players first name:</label>
            <input type="text" id="player2" name="player2" size="17"  maxlength="17" value="Enter Name" class="textbox" />
    </p>
        <input type="submit" name="submit" value="Start Playing!" />


    </form>
</body>

</html>

第二页:

$addScore1 = $_POST['addScore1'];
$addScore2 = $_POST['addScore2'];

$oldScore1 = $_POST['oldScore1'];
$oldScore2 = $_POST['oldScore2'];

$curr1=$_COOKIE["score1"]+$addScore1;
$curr2=$_COOKIE["score2"]+$addScore2;
setcookie("score1", $_COOKIE["score1"]+$addScore1, time()+3600);
setcookie("score2", $_COOKIE["score2"]+$addScore2, time()+3600);

//Reset cookies if reset button is 't', which makes it clear scores
if ($clse = t){
setcookie ("score1", "", time() - 3600);
setcookie ("score2", "", time() - 3600);
}


// Generate HTML form
?>
<!DOCTYPE HTML>
<html>
    <head>
        <title>Score Add</title>
        <link rel=StyleSheet href="style.css" type="text/css">
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    </head>

    <body>
    <form method="post" action=" ">

     <p class="par">
            <label for="addScore1">Enter your score, <?php echo $player1; ?>:</label>
            <input type="text" name="addScore1" id="addScore1" class="textbox" />
            <input type="hidden" name="oldScore1" id="oldScore1" value="<?php echo $oldscore1; ?>" />
        <input type="submit" value="Add Score!" />
    </p>

    <p class="par">
        <label for="addScore2">Enter your score, <?php echo $player2; ?>:</label>
        <input type="text" name="addScore2" id="addScore2" class="textbox"/>
        <input type="hidden" name="oldScore2" id="oldScore2" value="<?php echo $oldscore2; ?>" />
            <input type="submit" value="Add Score!"/>
        </form>
    </p>

         <form method="post" action=" ">
         <input type="hidden" name="clsc" id="clsc" value="t" />
         <input type="submit" value="Clear Scores" />
         </form>
<!--Shows player and score-->
    <p class="par"><?php echo $player1;?>:<?php echo $curr1?></p>
    <p class="par"><?php echo $player2;?>:<?php echo $curr2?></p>
    </body>
</html>
4

2 回答 2

1

不要为此使用cookies。启动 a$_SESSION并将信息存储在其中,然后$_SESSION在下一页上将其回显。

于 2013-03-06T02:23:06.363 回答
0

您可以为所有数据制作表临时文件,因此您选择全部,并在使用它时制作 ajax '$_session' 也是一种好方法:D

于 2013-03-06T02:29:49.697 回答