我在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 ";mysql_close (con);?>
您的php
没有被您的web引擎渲染。它需要有一个*.php扩展名,并在处理它的服务器上。
我猜这和多行
有关 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>
,