0

我在 HTML 表中显示 MySQL 记录时遇到问题

这是代码:

    <html>
<head>
</head>
<body>
<?php
                        $con = mysql_connect("localhost", "root", "");
                        if (!con) {
                        die ("Can not connect: " . mysql_error());
                        }

                        mysql_select_db ("regform", $con);

                        $sql = "SELECT * FROM contacts";
                        $myData = mysql_query($sql, $con);
                      echo 'test';    
                        echo "<table border = '1'>

                        <tr>
                        <th>Name</th>
                        <th>Lastname</th>
                        <th>Phone</th>
                        <th>Email</th>
                        <th>Comment</th>
                        </tr>";

                        while($record = mysql_fetch_array($myData)) {
                        echo "<tr>";
                        echo "<td>" . $record['Name'] . "</td>";
                        echo "<td>" . $record['Lastname'] . "</td>";
                        echo "<td>" . $record['Phone'] . "</td>";
                        echo "<td>" . $record['Email'] . "</td>";
                        echo "<td>" . $record['Comment'] . "</td>";
                        echo "</tr>";

                        }

                        echo "</table>";

                        mysql_close ($con);

                        ?>
</body>
</html>

我在浏览器上得到这个:

姓名 姓氏 电话 电子邮件 评论 "; while($record = mysql_fetch_array($myData)) { echo ""; echo "" . $record['Name'] . ""; echo "" . $record['Lastname'] . ""; echo "" . $record['Phone'] . ""; echo "" . $record['Email'] . ""; echo "" . $record['Comment'] . ""; echo " "; } 回声 ""; mysql_close ($con); ?>

4

2 回答 2

2

php的网络引擎没有呈现您的内容。它需要具有 *.php 扩展名并位于处理它的服务器上。

于 2013-03-22T19:58:48.107 回答
-1

我想这与多线有关

             echo "<table border = '1'>

                    <tr>
                    <th>Name</th>
                    <th>Lastname</th>
                    <th>Phone</th>
                    <th>Email</th>
                    <th>Comment</th>
                    </tr>";

也许你试试这个:

echo <<<END
<table border = '1'>

                    <tr>
                    <th>Name</th>
                    <th>Lastname</th>
                    <th>Phone</th>
                    <th>Email</th>
                    <th>Comment</th>
                    </tr>

结尾;

于 2013-03-22T20:01:44.460 回答