PHP代码以HTML格式显示 [英] PHP Codes are displaying in HTML

查看:88
本文介绍了PHP代码以HTML格式显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码从数据库表中获取数据:

 <!DOCTYPE HTML> 
< html>
< head>
< title>搜寻资料< / title>
< / head>
< body>
< table>
< tr>
< td align =center> EMPLOYEES DATA< / td>
< / tr>
< tr>
< td>
< table border =1>
< tr>
< td> NAME< / td>
< td> EMPLOYEES< br> NUMBER< / td>
< td> ADDRESS< / td>
< / tr>
<?php
//使用基于字段名称的序列搜索数据的示例
//search.php
mysql_connect(localhost,root, ); //数据库连接
mysql_select_db(db_psu_online);

$ order =SELECT * FROM tb_income_statement_igp_fields;
//为了搜索数据
//在定单变量中声明

$ result = mysql_query($ order); ($ data = mysql_fetch_row($ result)){
echo //(
// //命令执行结果被保存为
//在$ result
$ b变量中) < TR>< TD> $数据[1]; / TD>< TD> $数据[0]< / TD>< TD> $数据[2]< / TD>< / TR>中);
}
?>
< / table>
< / td>
< / tr>
< / table>
< / body>
< / html>

以上代码的输出是这样的:

不知道为什么字符:<$ c $

解决方案

您是否正在保存文件扩展名为 .php ?是否在您的服务器上安装并启用了PHP?



至少有一个这些是否,因为你所看到的是HTML中的原始PHP输出 - 如果你使用浏览器的View Source,你会清楚地看到它。


I am using the following code to fetch data from a database table:

<!DOCTYPE HTML>
<html>
    <head>
        <title>Search data</title>
    </head>
    <body>
        <table>
            <tr>
                <td align="center">EMPLOYEES DATA</td>
            </tr>
            <tr>
        <td>
        <table border="1">
            <tr>
            <td>NAME</td>
            <td>EMPLOYEES<br>NUMBER</td>
            <td>ADDRESS</td>
            </tr>
    <?php
        //the example of searching data with the sequence based on the field name
        //search.php
        mysql_connect("localhost","root","");//database connection
        mysql_select_db("db_psu_online");

        $order = "SELECT * FROM tb_income_statement_igp_fields";
        //order to search data
        //declare in the order variable

        $result = mysql_query($order);  
        //order executes the result is saved
        //in the variable of $result

        while($data = mysql_fetch_row($result)){
            echo("<tr><td>$data[1]</td><td>$data[0]</td><td>$data[2]</td></tr>");
        }
    ?>
        </table>
        </td>
        </tr>
        </table>
    </body>
</html>

The output of the code above is this:

I don't know why the characters: "); } ?> are being printed.

解决方案

Are you saving the file with the extension .php? Is PHP installed and enabled on your server?

The answer to at least one of these is "no", because what you are seeing is the raw PHP output in the HTML - if you use the browser's View Source, you'd see that clearly.

这篇关于PHP代码以HTML格式显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆