简体   繁体   English

使用wamp服务器时PHP脚本不起作用

[英]PHP script doesn't work when using wamp server

I installed wamp server on my windows 7 machine. 我在我的Windows 7机器上安装了wamp服务器。 It shows that all the services are running. 它表明所有服务都在运行。 It has Apache running, PHP running and also MySQL. 它有Apache运行,PHP运行以及MySQL。 I have the latest Chrome browser installed. 我安装了最新的Chrome浏览器。

I am trying to run the following code on the website, but I just get the basic html page without the PHP script. 我试图在网站上运行以下代码,但我只是得到没有PHP脚本的基本html页面。

Here is my code: 这是我的代码:

<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>

I looked around and they suggested me to install PHP, Apache and MySQL. 我环顾四周,他们建议我安装PHP,Apache和MySQL。 I have all three running with phpMyAdmin using wamp server. 我有三个使用wamp服务器运行phpMyAdmin。 What am I missing? 我错过了什么?

I fixed the issues with testing being regarded as not a string and added error reporting, but I still don't see testing being displayed on the webpage. 我修复了测试被认为不是字符串并添加错误报告的问题,但我仍然没有看到测试显示在网页上。

As per your original post - What @JayBlanchard said to use in regards to using error reporting, would have triggered an Undefined constant testing notice. 根据您的原始帖子 - @JayBlanchard在使用错误报告方面所说的内容,会触发未定义的常量测试通知。

Therefore, you need to wrap the word "testing" in quotes: 因此,您需要在引号中包含“testing”一词:

echo "testing";

Add error reporting to the top of your file(s) which will help find errors. 错误报告添加到文件的顶部,这将有助于查找错误。

<?php 
error_reporting(E_ALL);
ini_set('display_errors', 1);

// rest of your code

Sidenote: Error reporting should only be done in staging, and never production. 旁注:错误报告应该只在暂存中完成,而不是生产。


Consult the manual on strings: 查阅字符串手册:

and on constants: 和常数:

If you want to use a constant all you need to do is define it: 如果你想使用常量,你需要做的就是定义它:

define('testing', 'this part gets printed, not the name of the constant');

The accepted convention is to use upper case words for the name of the constant, so rather than 'testing' it would be 'TESTING'. 接受的约定是使用大写单词作为常量的名称,因此不是“测试”它将是“测试”。

define('TESTING', 'this part gets printed, not the name of the constant');

Then you can use the constant: 然后你可以使用常量:

echo TESTING; // no quotes, echos 'this part gets printed, not the name of the constant'

Edit: 编辑:

as per your edit: Is your file extension in fact .php and how are you accessing it? 根据您的编辑:您的文件扩展名实际上是.php ,您是如何访问它的? as http://localhost/file.php or as file:///file.php ? http://localhost/file.phpfile:///file.php

OP: it looks like file:///C:/xy OP:它看起来像file:/// C:/ xy

  • It should be http://localhost/file.php 它应该是http://localhost/file.php

That should read: 那应该是:

echo "testing";

you are missing the quotes. 你错过了报价。

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

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