Home >Backend Development >PHP Problem >How to call php from html
html itself cannot handle dynamic requests. To accomplish this, JavaScript is generally used. When generating a static web page, you can generate a corresponding JavaScript file reference for the HTML page based on the database ID. For example, if the page is 123.html, then generate a
<script type="text/javascript" src="click.php?id=123"></script>
on this page, and then on the click.php page, just process and operate the database according to the syntax of PHP.
Related recommendations: "php Getting Started Tutorial"
You cannot directly call php files in static pages, but you can use js calling method to call php files, you can also use ajax calls php file.
Give a simple example to illustrate: Use the following code in page a.html to pass the action=test parameter to b.php.
The Javascript code is as follows:
<script type="text/javascript" src="b.php?action=test"></script>
There is such a PHP code in b.php:
<?php $action=$_GET['action']; echo "document.write('".$action."');n"; ?>
The above is the detailed content of How to call php from html. For more information, please follow other related articles on the PHP Chinese website!