php - 个人项目: using while loops

标签 php html error-handling

我是PHP新手。我正在尝试创建一个简单的个人项目,当用户从浏览器刷新页面时,几个硬币会在页面中移动。我不断收到奇怪的错误()。
这是我的文件的样子:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <title>Treasure Map</title>
    </head>
    <body style="background-image:url(Bluemap.jpg); background-repeat: no-repeat">

            <?php
        $numberOfCoins = rand(3, 10);

        while ($numberOfCoins) {
            $xPosition = rand("10", "650");
            $yPosition = rand("10", "400");
            print '<div style="position: absolute;';
            print 'left:' . $xPosition . 'px;';
            print 'top:' . $yPosition . 'px">';
            print '<img src="goldCoin.png" height="50px"/>';
            print '</div>';
            $numberOfCoins--;
        }
        ?>

    </body>
</html>

我究竟做错了什么?

最佳答案

该文件是HTML文档,因此无法运行PHP代码。

您需要将其从index3.html重命名为index3.php,并确保在运行PHP的服务器上运行它

关于php - 个人项目: using while loops,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23858502/

相关文章:

php - SilverStripe SiteConfig 标题字段操作

PHP 多重查询问题

php - mysql自增和唯一字段

javascript - 为什么 anchor href 显示片段的完整路径?

c# - 使用 .NET 任务并行库捕获错误

swift - 在 swift 中选择表格菜单项时应用程序崩溃

php - 我的错误消息在其左侧的错误消息下方进行了格式化

php - mysqli_error() 正好需要 1 个参数,给定 0

php - 网络连接不稳定的文件上传解决方案

html - 如何在 Bulma 中集中对齐列?