如何通过PHP加载HTML文件并从mySQL插入数据? [关闭]

I have an HTML file we'll call it dashboard.html.

I have a PHP file called index.php that will load on the webserver by default.

I have a mySQL database called myDb.

From index, how do I load the HTML file dashboard and INSERT data from my SQL database into the appropriate places?

Right now the html file may have a line that reads: John Doe . Instead of having a name in that span, I need to replace it with the appropriate PHP to insert the appropriate name from my SQL database. I actually already know how to echo the data from mySQL to the . What I don't know how to do is load the HTML from the PHP file.

There are many ways to it:

1st: Put your html code into your index.php and echo your data on the right place. Simpliest one.

2nd: Use Keys in your html and replace it with the data. For example:

In dashboard.html

<input type="text" value="%DATA%" />

in your index.php

$holeFile = file_get_contents('dashboard.html');
$holeFile = str_replace('%DATA%', $resultSet['column']);
// ...

If you choose this way, there are already nice template engines like smarty.

3rd: Use DOM Objects in PHP and replace it. Mostly the same as 2nd, but in a nicer way. See here

Just follow follow the steps

index.php

$name= "xxxxx";
include "dashboard.php";

dashboard.php

<html>
<head></head>
<body>
Hello,<b><?php print($name);?></b>
</body>
</html>

Change your file name dashboard.html to dashboard.php and put $name variable in index.php file first then include dashboard.php file. Hope it will solve your problem