我在我的Windows7机器上安装了WAMP服务器。它显示所有服务都在运行。它运行apache、php和mysql。我安装了最新的chrome浏览器。
我试图在网站上运行下面的代码,但是我只得到了没有php脚本的基本html页面。
这是我的代码:

<html>

<head>
    <title>Php Tutorial</title>
</head>

<body>

    <h3>Php tutorials</h3>
    <hr>

    <a href="?page=home">Home</a>
    <a href="?page=tutorial">Tutorials</a>
    <a href="?page=about">About</a>
    <a href="?page=contact">Contact</a>
    <hr>

    <?php
    error_reporting(E_ALL);
    ini_set('display_errors', 1);
    echo "testing";
    print_r($_REQUEST);

    ?>

</body>

我环顾四周,他们建议我安装php、apache和mysql。我使用wamp服务器使用phpmyadmin运行这三个文件。我错过了什么?
我修复了测试被视为非字符串的问题,并添加了错误报告,但我仍然没有看到测试显示在网页上。

最佳答案

As per your original post@jayblanchard所说的关于使用错误报告的内容,会触发一个未定义的常量测试通知。
因此,您需要用引号将“testing”一词括起来:

echo "testing";

error reporting添加到文件顶部,这将有助于查找错误。
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

// rest of your code

附带说明:错误报告只应在暂存中完成,而不应在生产中完成。
请参阅字符串手册:
https://php.net/language.types.string
在常数上:
http://php.net/manual/en/language.constants.php
如果要使用常量,只需定义它:
define('testing', 'this part gets printed, not the name of the constant');

公认的惯例是使用大写字母作为常量的名称,因此它不是“testing”,而是“testing”。
define('TESTING', 'this part gets printed, not the name of the constant');

然后可以使用常数:
echo TESTING; // no quotes, echos 'this part gets printed, not the name of the constant'

编辑:
根据您的编辑:您的文件扩展名实际上是.php吗?您是如何访问它的?是http://localhost/file.php还是file:///file.php
op:看起来像file:///c:/xy
应该http://localhost/file.php

10-07 12:03
查看更多