Home > Backend Development > PHP Problem > How to call php from html

How to call php from html

爱喝马黛茶的安东尼
Release: 2023-02-27 16:24:01
Original
4857 people have browsed it

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>
Copy after login

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>
Copy after login

There is such a PHP code in b.php:

<?php
    $action=$_GET[&#39;action&#39;];     
    echo "document.write(&#39;".$action."&#39;);n";    
?>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template