在HTML表中显示MySQL记录。什么失败了?

时间:2013-03-22 19:55:31

标签: php html mysql

我在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“”;} echo“”; mysql_close($ con);?&gt;

2 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分:-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>

END;