【发布时间】:2017-08-15 08:30:36
【问题描述】:
所以我已经在使用 post 将 HTML 表单中的数据插入到在 XAMPP 上运行的 MySQL 数据库中,然后我将如何在表格中的另一个 HTML 页面上显示这些数据?当我尝试从 localhost 运行它时,它会出现一个空白页面,顶部有一行代码。我是新手,这是我的代码:我做得对吗?
<html>
<head>
</head>
<body>
<?php
$con = mysql_connect('localhost', 'root', '');
if (!$con){
die("Can not connect: " . mysql_error());
}
mysql_select_db("form_process", $con);
$sql = "SELECT * FROM `form_submissions`";
$myData = mysql_query($sql,$con);
echo "<table border=1>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Phone Number</th>
<th>Class interested in</th>
</tr>";
while($row= mysql_fetch_array($result)){
echo "<tr>";
echo "<td>" . $record['First'] . "</td>";
echo "<td>" . $record['Last'] . "</td>";
echo "<td>" . $record['Phone'] . "</td>";
echo "<td>" . $record['Class'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close();
?>
</body>
</html>
【问题讨论】:
-
尝试:
while($row= mysql_fetch_array($myData)){- 变量$result未以任何方式设置。尝试阅读您的错误日志,它会让您知道此类问题:) -
每次在新代码中使用the
mysql_数据库扩展a Kitten is strangled somewhere in the world 时,它都会被弃用,并且已经存在多年,并且在 PHP7 中永远消失了。如果您只是学习 PHP,请花精力学习PDO或mysqli数据库扩展和预处理语句。 Start here -
将error reporting 添加到您的文件顶部测试时 在您打开PHP 标记之后,例如
<?php error_reporting(E_ALL); ini_set('display_errors', 1);以查看它是否产生任何结果。然后你会看到你的错误,以便你修复它们
标签: javascript php html mysql xampp