在html页面上显示来自mysql/phpmyadmin的数据
我是在html页面上显示来自mysql/phpmyadmin的数据,php,html,Php,Html,我是PHP的初学者。 我尝试将PHP放入HTML文件中,以便从名为test的数据库和名为myemployee的表中调用数据。 我尝试了其他论坛的所有推荐,但仍然没有在表中显示,而是显示了代码。 遵循我的代码。我的代码有问题吗 即使我输入PHP文件,然后像这样从HTML文件调用,它仍然不起作用 <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Home&
PHP
的初学者。
我尝试将PHP放入HTML文件中,以便从名为test的数据库和名为myemployee的表中调用数据。我尝试了其他论坛的所有推荐,但仍然没有在表中显示,而是显示了代码。
遵循我的代码。我的代码有问题吗 即使我输入PHP文件,然后像这样从HTML文件调用
,它仍然不起作用
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Home</title>
<link href="style/index-layout.css" rel="stylesheet" type="text/css" />
<link href="style/homepage-layout.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!--right-->
<div id="body">
<div id="left">
<br /><br />
<P ><B><h3>Progress</h3></FONT></B></P>
</div></div>
<?php
$username = "root";
$password = "";
$host = "localhost";
$connector = mysql_connect($host,$username,$password)
or die("Unable to connect");
echo "Connections are made successfully::";
$selected = mysql_select_db("test", $connector)
or die("Unable to connect");
//execute the SQL query and return records
$result = mysql_query("SELECT * FROM myemployee");
?>
<table>
<thead>
<tr>
<th>Employee_id</th>
<th>Employee_Name</th>
<th>Employee_dob</th>
<th>Employee_Adress</th>
<th>Employee_dept</th>
<th>Employee_salary</th>
</tr>
</thead>
<tbody>
<?php
while( $row = mysql_fetch_assoc( $result ) ){
echo "$row";
echo
"<tr>
<td>{$row['employee_id']}</td>
<td>{$row['employee_name']}</td>
<td>{$row['employee_dob']}</td>
<td>{$row['employee_addr']}</td>
<td>{$row['employee_dept']}</td>
<td>{$row['employee_sal']}</td>
</tr>";
}
?>
</tbody>
</table>
<?php mysql_close($connector); ?>
<br/><br/>
</body>
</html>
家
进展情况
雇员身份证
雇员姓名
雇员
员工地址
员工部
员工工资
检查您的文件扩展名。PHP(默认情况下)只能在扩展名为.PHP的文件中运行。无需将其调用到html文件。您可以将整个代码放在一个.php文件中并运行该php文件。
我只是检查了你的代码,我把它放在一个php文件中,并做了一些更改。它工作得很好(没有明显的风格)。
代码如下:
<?php
$username = "root";
$password = "";
$host = "localhost";
$connector = mysql_connect($host, $username, $password)
or die("Unable to connect");
$selected = mysql_select_db("sample", $connector)
or die("Unable to connect");
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Home</title>
<link href="style/index-layout.css" rel="stylesheet" type="text/css" />
<link href="style/homepage-layout.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!--right-->
<div id="body">
<div id="left">
</div></div>
<?php
//execute the SQL query and return records
$result = mysql_query("SELECT * FROM alte_brand");
?>
<table>
<thead>
<tr>
<th>Employee_id</th>
<th>Employee_Name</th>
</tr>
</thead>
<tbody>
<?php
while ($row = mysql_fetch_assoc($result)) {
echo
"<tr>
<td>{$row['bid']}</td>
<td>{$row['bname']}</td>
</tr>";
}
?>
</tbody>
</table>
</body>
</html>
<?php mysql_close($connector); ?>
家
雇员身份证
雇员姓名
您可以将此指令添加到.htaccess文件中
AddType application/x-httpd-php .html
注意:PHP MySQL现在被弃用,取而代之的是MySQLi函数。谢谢。!它起作用了。但是,假设我有一个具有适当布局的.html,是否可以显示数据表?谢谢again@AnimAnwar问题是php标记在html页面中不起作用。就我在php的工作而言。我从未使用过带有php标记的html页面。只需使用普通的php页面。在浏览器中,在显示.php文件类型之前,no将知道页面是否为php/html。它应该在那里,是的。请确保在Web服务器中启用它。有关apache,请参阅